iphone - UIBarButtonItem:setBackgroundVerticalPositionAdjustment not working properly with custom button -


i have following code customize display of uibarbuttonitem (locationbutton):

    uibutton *locationbuttonaux = [uibutton buttonwithtype:uibuttontypecustom];     [locationbuttonaux setframe:cgrectmake(0, 0, location_button_width, location_button_height)];     [locationbuttonaux setbackgroundimage:[uiimage imagenamed:@"location_button.png"] forstate:uicontrolstatenormal];     [locationbuttonaux setbackgroundimage:[uiimage imagenamed:@"location_button.png"] forstate:uicontrolstatehighlighted];     [locationbuttonaux addtarget:self action:@selector(userlocation) forcontrolevents:uicontroleventtouchupinside];     uibarbuttonitem *locationbutton = [[uibarbuttonitem alloc] initwithcustomview:locationbuttonaux];     uibarbuttonitem * item = [[uibarbuttonitem alloc] initwithtitle:@"title"                                                               style:uibarbuttonitemstyledone                                                              target:nil action:@selector(somemssage)];     [locationbutton setbackgroundverticalpositionadjustment:-20.0 forbarmetrics:uibarmetricsdefault];     self.navigationitem.rightbarbuttonitem = locationbutton; 

and want adjust position of button navigationbar, because navigationbar taller normal (is customized using appeareance).

i'm using method setbackgroundverticalpositionadjustment, can see in code, that. not working @ uibarbuttonitem, no matter offset put there, button appear close bottom of bar (snapshot). but, if use normal uibarbuttonitem normal style (the 1 called button) can see how position of button altered offset of -20. strange... ideas?

thank you!

enter image description here

perhaps work you:

uiview *rightview = [[uiview alloc] initwithframe:cgrectmake(0, 0, 150, 30)]; //change frame counteract taller navbar [rightview addsubview:locationbuttonaux]; uibarbuttonitem *rightbarbuttonitem = [[uibarbuttonitem alloc] initwithcustomview:rightview]; self.navigationitem.rightbarbuttonitem = rightbarbuttonitem; 

hope helps


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

What is the difference between data design and data model(ERD) -

ios - Can NSManagedObject conform to NSCoding -