将iOS TabBar项目标题调整到其中心
//如何使第一个选项卡项标题“Article View”位于中间位置,而不向选项卡项添加任何//图像 //与下面的选项卡栏项目屏幕截图类似将iOS TabBar项目标题调整到其中心,ios,Ios,//如何使第一个选项卡项标题“Article View”位于中间位置,而不向选项卡项添加任何//图像 //与下面的选项卡栏项目屏幕截图类似 //TabBarController code: self.delegate=self; self.tabBarController.tabBar.delegate=self; CGRect viewFrame=self.tabBar.frame; viewFrame.origin.y -=0;![enter image description here
//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;
}
将
initWithNibName
方法替换为
[1]: http://i.stack.imgur.com/xBpVH.png
Thanks in advance.
self.tabBarItem.imageInsets=UIEdgeInsetsMake(5,0,-5,0)代码>此行按以下方式调整tabBarItem的图像位置:
将图像沿x方向“+5”和y方向“-5”从
默认位置
玩UIEdgeInsetsMake
并享受乐趣。干杯。谢谢你帮了我,伙计。。我要求你不要在图片上工作,而是我应该改变标题的位置,然后它就固定了。很高兴我能帮上忙。如果你愿意,请检查一下答案;):)谢谢你的提问,谢谢你的回答
- (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;
}