objective c - UILabel on a UIToolbar (programmatically) doesn't display the label -


i have following code in -viewdidload: :

self.navigationcontroller.toolbarhidden = no;  uibarbuttonitem *sharebutton = [[uibarbuttonitem alloc]    initwithbarbuttonsystemitem:uibarbuttonsystemitemaction target:self action:@selector(sendemail:)];      uibarbuttonitem *spacer1 = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace target:nil action:nil];      uilabel *label = [[uilabel alloc] initwithframe:cgrectmake(0.0 , 25, self.view.frame.size.width, 21.0f)];     label.backgroundcolor = [uicolor clearcolor];     label.textcolor = [uicolor whitecolor];     label.text = @"text-here";     label.userinteractionenabled = no;     label.font = [uifont systemfontofsize:18.0];     label.textalignment = nstextalignmentcenter;      uibarbuttonitem *labelitem = [[uibarbuttonitem alloc] initwithcustomview:label];      self.navigationcontroller.toolbaritems = [nsarray arraywithobjects:sharebutton, spacer1, labelitem, nil]; 

however, when load app, toolbar displays sharebutton, linked sharing contents of app through e-mail. label doesn't appear (and want to). i've copied exact code other questions asked on stackoverflow, , everywhere same answer...is there different this?

i assume since share button works, toolbar works fine. other answers questions mine have produced [self.navigationcontroller.view addsubview:toolbarobj];, used toolbar integrated navigation controller.

the spacer...well, don't know how spacer me @ point. right now, if understand right, spacer push label item far right, correct? wouldn't space out objects evenly? love have label in center of toolbar.

help , explanation appreciated.

when run code doesn't show either label or button. if make change below, both appear:

change:

self.navigationcontroller.toolbaritems = [nsarray arraywithobjects:sharebutton, spacer1, labelitem, nil]; 

to:

self.toolbaritems = [nsarray arraywithobjects:sharebutton, spacer1, labelitem, nil]; 

if want label in middle, make smaller (i divided view width 2) , add second spacer on other side of it:

self.toolbaritems = [nsarray arraywithobjects:sharebutton, spacer1, labelitem, spacer2, nil]; 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -