【问题标题】:Increased height of one of the tab bar items增加标签栏项目之一的高度
【发布时间】:2013-02-04 00:49:53
【问题描述】:
我创建了一个基于标签的应用,它有 5 个标签。
我希望第三个标签栏项的高度高于所有其他标签。
第三个标签栏项目的大小将始终大于其他标签。
如何在基于标签的应用程序中执行此操作?没有自定义标签栏是否可能?
请帮忙
提前致谢
【问题讨论】:
-
你的应用可能会因为违反HIG:A tab bar does not change its opacity or height, regardless of device orientation.而被苹果拒绝
-
标签:
iphone
ios
objective-c
uitabbar
uitabbaritem
【解决方案1】:
您可以通过叠加自定义视图或按钮轻松实现此效果。这是我在应用程序中为实现此效果所做的工作(如下所示)。我认为没有额外的子视图是不可能做到这一点的。
UIButton *middleButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[middleButton addTarget:self action:@selector(tappedMiddleButton:) forControlEvents:UIControlEventTouchUpInside];
CGRect frame;
frame.size.height = 54;
frame.size.width = 72;
frame.origin.x = ceil(0.5 * (tabBarController.view.bounds.size.width - frame.size.width));
frame.origin.y = tabBarController.tabBar.bounds.size.height - frame.size.height;
[middleButton setFrame:frame];
[[tabBarController tabBar] addSubview:middleButton];
然后你可以调用你的方法:
-(void)tappedMiddleButton:(id)sender {
}
在该方法中,您可以设置标签栏的选定索引:
[tabBarController setSelectedIndex:2];