objective c - Centering on a UIToolBar with a UIToolbarButton on either side -
i trying center text on uitoolbar button on either side, having problems.
i have following code:
uitoolbar *toolbar = [[uitoolbar alloc] initwithframe:toolbarinitialframe]; toolbar.barstyle = uibarstyleblacktranslucent; uilabel * label = [[uilabel alloc] initwithframe:cgrectmake(0, 0, 200, 25)]; [label settext:@"title"]; [label setbackgroundcolor:[uicolor clearcolor]]; [label settextcolor:[uicolor whitecolor]]; [label setfont:[uifont boldsystemfontofsize:16]]; uibarbuttonitem * labelemu=[[uibarbuttonitem alloc] initwithcustomview:label]; uibarbuttonitem *cancelbutton = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemcancel target:self action:@selector(cancelalarmanddismissdatepicker:)]; uibarbuttonitem *spacer = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace target:nil action:nil]; uibarbuttonitem *donebutton = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemdone target:self action:@selector(setalarmanddismissdatepicker:)];
so want cancel button (cancelbutton
) on left, title (labelemu
) centered in middle, , done button (donebutton
) on right. this:
|[cancel] title [done]|
i hoping achieve this:
[toolbar setitems:[nsarray arraywithobjects: cancelbutton, spacer, labelemu, spacer, donebutton, nil]];
but unfortunately this:
|[cancel]title [done]|
after playing about, ive found line:
[toolbar setitems:[nsarray arraywithobjects: cancelbutton, spacer, labelemu, spacer, nil]];
...produces this:
|[cancel] title |
where title centered, ignoring fact cancel button there. when this:
[toolbar setitems:[nsarray arraywithobjects: spacer, labelemu, spacer, donebutton, nil]];
...it produces this:
| title [done]|
where title centered in space between far left edge , right side of done button. not ignoring done button in same way ignores cancel button.
can point me in right direction after? sorry naff ascii diagrams! :)
maybe try using:
[[uibarbuttonitem alloc] initwithtitle:@"yourtitle" style:uibarbuttonitemstyleplain target:nil action:nil];
it might if uitollbar in charge on label.
edit try adding:
[label sizetofit];
before adding tollbar
Comments
Post a Comment