ios - Is there a way to have custom UIBarButtonItems in a Toolbar that go against the HIG? -
these human interface guidelines uitoolbar
icons, , bar button icons.
i want doesn't follow hig.
basically want solid rounded , flat colored uibutton
, text overtop. (however, don't want text apart of image obvious reasons).
can accomplished?
can draw uibarbuttonitem
.cornerradius = 5.0. believe that'suibutton
only.
or can use masked png image uibarbuttonitem
, apply tintcolor change images mask, , overlay text on top?
or have fake/mimic creating auitoolbar
, , create 44 pixel lightgreyuiview
@ bottom of yourview
?
how can accomplished, , rejected violating hig?
you can go uitoolbar
& have uibarbuttonitem
added that. since uibarbuttonitem
inherited uibaritem
& nsobject
, have minimal features modify.
use following code initiate items in uitoolbar
way have custom uibutton uitoolbaritem
.
to change button background color different state, may have hold button state toggles in array, , change color depending on state
here fresh code that:
uitoolbar *toolbar = [[uitoolbar alloc]initwithframe:cgrectmake(0,55, self.view.bounds.size.width, 55)]; toolbar.tintcolor = [uicolor redcolor]; [self.view addsubview:toolbar]; nsmutablearray *temparray = [[nsmutablearray alloc]init]; buttonstatearray = [[nsmutablearray alloc]init]; for(int =0; < 3; i++){ uibutton *tempbutton = [[uibutton alloc]initwithframe:cgrectmake(0, 0, 100, 30)]; tempbutton.backgroundcolor = [uicolor redcolor]; tempbutton.layer.cornerradius = 8; tempbutton.layer.borderwidth = 2; tempbutton.tag = i; tempbutton.layer.bordercolor = [uicolor blackcolor].cgcolor; [tempbutton settitle:[nsstring stringwithformat:@"hello %d", i] forstate:uicontrolstatenormal]; [tempbutton addtarget:self action:@selector(displaytapped:) forcontrolevents:uicontroleventtouchupinside]; [temparray addobject:[[uibarbuttonitem alloc]initwithcustomview:tempbutton]]; [buttonstatearray addobject:[nsnumber numberwithbool:no]]; } [toolbar setitems:temparray];
now target method of button
-(void)displaytapped:(uibutton *)sender{ bool state = [[buttonstatearray objectatindex:sender.tag] boolvalue]; [buttonstatearray replaceobjectatindex:sender.tag withobject:[nsnumber numberwithbool:!state]]; if(!state){ sender.backgroundcolor = [[uicolor blackcolor] colorwithalphacomponent:0.5]; }else { sender.backgroundcolor = [uicolor redcolor]; }
}
updated screen here
Comments
Post a Comment