ios - UIBarButtonItems with background images -


we have "bottom bar" in our app @ moment uiview , defined on place leads inconsistency etc...

i'm trying replace use of uitoolbar , uibarbuttonitems can customise appearance uiappearance protocol.

the buttons use in tool bar have background image made of resizable image (defined in asset catalog).

what want this...

desired result

the buttons nicely centred between top , bottom of tool bar.

however, happens when set background image using uiappearance protocol this...

actual result

the buttons vertically aligned off centre.

it seems text in same place , background being applied around text text lower centre. no bg makes sense bg doesn't work.

i change frame in code of every button not ideal inconsistency problem i'm trying solve.

is there way change instances of uibarbuttonitem in 1 place?

i tried adding transparency bottom of image "push upwards" didn't have effect.

update show problem in place

in enw project embed view controller in navigation controlle rand use code...

- (void)viewwillappear:(bool)animated {     [super viewwillappear:animated];      [self.navigationcontroller settoolbarhidden:no animated:animated]; }  - (nsarray *)toolbaritems {     return @[              [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemfixedspace target:nil action:nil],              [[uibarbuttonitem alloc] initwithtitle:@"hello" style:uibarbuttonitemstyledone target:nil action:nil],              [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemfixedspace target:nil action:nil],              [[uibarbuttonitem alloc] initwithtitle:@"world!" style:uibarbuttonitemstyledone target:nil action:nil],              [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace target:nil action:nil],              [[uibarbuttonitem alloc] initwithtitle:@"goodbye!" style:uibarbuttonitemstyledone target:nil action:nil],              [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemfixedspace target:nil action:nil]              ]; } 

the result is...

default toolbar style

then use uiappearance code...

[[uitoolbar appearance] settintcolor:[uicolor whitecolor]]; [[uitoolbar appearance] setbartintcolor:[uicolor colorwithred:0.15 green:0.2 blue:0.85 alpha:1.0]]; 

and result is...

blue toolbar white tint colour.

this looks fine when add background image...

resizable button image

with code...

[[uibarbuttonitem appearance] setbackgroundimage:[uiimage imagenamed:@"toolbarbuttonbackgroundenabled"] forstate:uicontrolstatenormal barmetrics:uibarmetricsdefault]; 

i see this...

button backgrounds below centre

i tried changing title position adjustment...

[[uibarbuttonitem appearance] settitlepositionadjustment:uioffsetmake(0, -5) forbarmetrics:uibarmetricsdefault]; 

but moves text inside button...

buttons offset titles

it doesn't move button background.

i can't find relating offset of buttons in toolbar appearance.

moving text

i wrong text staying int same place. text moves when add background bar button items...

merged image of , without background

i merged screenshots of toolbar , without button backgrounds. can see text moved downwards.

have tried [xyzbtn setimageedgeinsets:uiedgeinsetsmake(10, 10, 10, 10)]; or image size greater button's size, might affecting layout.


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -