iphone - Make custom back button's clickable area smaller in Navigation controller -
i've created custom button code below, clickable area big , goes beyond icon itself. know how set clickable area, or make same size image?
thanks
uiimage *buttonimage = [uiimage imagenamed:@"prefs"]; uibutton *button = [uibutton buttonwithtype:uibuttontypecustom]; [button setimage:buttonimage forstate:uicontrolstatenormal]; button.frame = cgrectmake(0, 0, buttonimage.size.width, buttonimage.size.height); [button addtarget:self action: @selector(handlebackbutton) forcontrolevents:uicontroleventtouchupinside]; uibarbuttonitem *custombaritem = [[uibarbuttonitem alloc] initwithcustomview:button]; self.navigationitem.leftbarbuttonitem = custombaritem;
the clickable area shown in red.
thanks!
if want prevent click other button add custom button uiview set view custom view barbuttonitem
your code become :
uiimage *buttonimage = [uiimage imagenamed:@"prefs"]; uibutton *button = [uibutton buttonwithtype:uibuttontypecustom]; [button setimage:buttonimage forstate:uicontrolstatenormal]; button.frame = cgrectmake(0, 0, buttonimage.size.width, buttonimage.size.height); [button addtarget:self action: @selector(handlebackbutton) forcontrolevents:uicontroleventtouchupinside]; uiview *view = [[uiview alloc] initwithframe:cgrectmake(0, 0, buttonimage.size.width, buttonimage.size.height)]; [view addsubview:button]; uibarbuttonitem *custombaritem = [[uibarbuttonitem alloc] initwithcustomview:view]; self.navigationitem.leftbarbuttonitem = custombaritem;
this should work worked me.
Comments
Post a Comment