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...
the buttons nicely centred between top , bottom of tool bar.
however, happens when set background image using uiappearance
protocol this...
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...
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...
this looks fine when add background image...
with code...
[[uibarbuttonitem appearance] setbackgroundimage:[uiimage imagenamed:@"toolbarbuttonbackgroundenabled"] forstate:uicontrolstatenormal barmetrics:uibarmetricsdefault];
i see this...
i tried changing title position adjustment...
[[uibarbuttonitem appearance] settitlepositionadjustment:uioffsetmake(0, -5) forbarmetrics:uibarmetricsdefault];
but moves text inside button...
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...
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
Post a Comment