ios - Why does adding imageview to navigation bar in storyboard remove navbar? -


i have working app tabbarcontroller based app. first viewcontroller uitableviewcontroller. 3 tabs have navigation bar on top, added object library. app looks like:

original uitableviewcontroller in first tab uinavbar

then wanted set image on navbar centered logo. looked around , found code looks this:

 uiimage *image = [uiimage imagenamed:@"icon57.png"];  uiimageview *imageview = [[uiimageview alloc] initwithimage: image];  self.navigationitem.titleview = imageview; 

or

[self.navigationcontroller.navigationbar setbackgroundimage:[uiimage imagenamed:@"icon57.png"] forbarmetrics:uibarmetricsdefault]; 

but didnt work. got empty white nav bar. decided add uiimageview navbar dragging in object library reason makes navbar disappear , end this:

after adding uiimageview uinavbar

why happen?

the way doing not supported in interface builder. encourage file radar support doing that. can accomplish via 2 different ways, 1 in code, other in ib.

through interface builder

you can drag uiview instance object library , drop center of nav bar. set view inside title area of bar. may take uiimageview instance , add subview of view added.

through code

you can set uiimageview through code, using titleview property of view controller's navigation item:

- (void)viewdidload {     [super viewdidload];      uiimage *logo = [uiimage imagenamed:@"logo.png"];     self.navigationitem.titleview = [[uiimageview alloc] initwithimage:logo]; } 

edit:

in order set on left side, you'll have wrap image view in uibarbuttonitem. can in ib using same procedure described above, or in code following:

- (void)viewdidload {     [super viewdidload];      uiimage *logo = [uiimage imagenamed:@"logo.png"];     uiimageview *imageview = [[uiimageview alloc] initwithimage:logo];         uibarbuttonitem *imagebutton = [[uibarbuttonitem alloc] initwithcustomview:imageview];      self.navigationitem.leftbarbuttonitem = imagebutton; } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -