objective c - Navbar Title Align Center -


appdelegate.m navbar customization:

[[uiapplication sharedapplication] setstatusbarstyle:uistatusbarstyleblackopaque]; [[uinavigationbar appearance] setbackgroundimage:[uiimage imagenamed:@"navbar"] forbarmetrics:uibarmetricsdefault]; [[uinavigationbar appearance] settitletextattributes: @{                             uitextattributetextcolor: [uicolor colorwithred:(56/255.0) green:(61/255.0) blue:(63/255.0) alpha:1],                             uitextattributetextshadowcolor: [uicolor graycolor],                             uitextattributetextshadowoffset: [nsvalue valuewithuioffset:uioffsetmake(0.0f, 1.0f)],                             uitextattributefont: [uifont fontwithname:@"proximanova-bold" size:15.0f]  }]; 

lviewcontroller.m navbar custom left/right buttons:

// left button uibutton *leftbutton =  [uibutton buttonwithtype:uibuttontypecustom]; [leftbutton setimage:[uiimage imagenamed:@"menu"] forstate:uicontrolstatenormal]; [leftbutton addtarget:self action:@selector(openleftmenu) forcontrolevents:uicontroleventtouchupinside]; [leftbutton setframe:cgrectmake(0, 0, 45, 44)]; self.navigationitem.leftbarbuttonitem = [[uibarbuttonitem alloc] initwithcustomview:leftbutton];  // right button uibutton *rightbutton =  [uibutton buttonwithtype:uibuttontypecustom]; [rightbutton setimage:[uiimage imagenamed:@"location"] forstate:uicontrolstatenormal]; [rightbutton addtarget:self action:@selector(openrightmenu) forcontrolevents:uicontroleventtouchupinside]; [rightbutton setframe:cgrectmake(0, 0, 45, 44)]; self.navigationitem.rightbarbuttonitem = [[uibarbuttonitem alloc] initwithcustomview:rightbutton]; 

result (title not centered):

title not centered

i tried lot of tips, worked:

working custom fonts on ios fraught peril when comes vertical orientation of text. best bet here embed title in uilabel, place uilabel in uiview, positioned appropriately. this:

uilabel *titlelabel = [[uilabel alloc] init]; titlelabel.text = @"test";  uiview *container = [[uiview alloc] initwithframe:cgrectmake(0.0f,                                                              0.0f,                                                              320.0f,                                                              44.0f)];  titlelabel.frame = …; // compute frame need based on chosen font, set                       // appropriately.  [container addsubview:titlelabel];  self.navigationitem.titleview = container; 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -