Adjust iOS TabBar item title to the centre of it -
//tabbarcontroller code: self.delegate=self; self.tabbarcontroller.tabbar.delegate=self; cgrect viewframe=self.tabbar.frame; viewframe.origin.y -=0;![enter image description here][1] viewframe.origin.x -=0; viewframe.size.height=30; self.tabbar.frame=viewframe; firstviewcontroller = [[firstviewcontroller alloc] initwithnibname:nil bundle:null]; secondviewcontroller = [[secondviewcontroller alloc] initwithnibname:nil bundle:null]; nsarray *twoviewcontrollers = [[nsarray alloc] initwithobjects: self.firstviewcontroller, self.secondviewcontroller, nil]; self.viewcontrollers=twoviewcontrollers; // ==================================================== // // firstviewcontroller code in initwithnibname: // // set title of first tabbar item: - (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { self.title = @"article view"; nslog(@"count = %d",[self.tabbarcontroller.tabbar.items count]); } homecoming self; }
//how can create first tabbar item title "article view" center without adding //image tabbaritem ?
// similar below tabbar items screenshot.
[1]: http://i.stack.imgur.com/xbpvh.png in advance.
replace initwithnibname
method
- (id)initwithnibname:(nsstring *)nibnameornil bundle:(nsbundle *)nibbundleornil { self = [super initwithnibname:nibnameornil bundle:nibbundleornil]; if (self) { self.title = @"article view"; self.tabbaritem.imageinsets = uiedgeinsetsmake(5, 0, -5, 0); nslog(@"count = %d",[self.tabbarcontroller.tabbar.items count]); } homecoming self; }
self.tabbaritem.imageinsets = uiedgeinsetsmake(5, 0, -5, 0);
line here adjusts position of image tabbaritem in manner :
shift image in x-direction '+5' , in y-direction '-5' default position.
play uiedgeinsetsmake
, have fun. cheers.
ios
No comments:
Post a Comment