增加其中一个标签栏项目的高度

iOS*_*Dev 2 iphone objective-c uitabbaritem uitabbar ios

我创建了一个基于标签的应用,它有5个标签.

我希望第三个标签栏项目的高度高于所有其他标签.

此第三个标签栏项的大小将始终保持大于其他标签.

如何在基于选项卡的应用程序中执行此操作?没有自定义标签栏可以吗?

请帮忙

提前致谢

Aar*_*ski 9

您可以通过覆盖自定义视图或按钮轻松实现此效果.这是我在应用程序中为实现此效果所做的事情(如下所示).我不相信没有额外的子视图就可以做到这一点.

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];
Run Code Online (Sandbox Code Playgroud)

然后你可以得到你的方法:

-(void)tappedMiddleButton:(id)sender {

}
Run Code Online (Sandbox Code Playgroud)

在该方法内部,您可以设置选项卡栏的选定索引:

[tabBarController setSelectedIndex:2];
Run Code Online (Sandbox Code Playgroud)