我想知道是否有办法完成只有大图标的标签栏,我在下面附上了一张图片供参考。我对创建自己的标签栏控制器以及自己管理视图控制器不感兴趣。
答案 0 :(得分:5)
这是我的解决方案,我创建了一个类,它是UITabBarController
。
<强> CustomTabBarController.h 强>
@interface CustomTabBarController : UITabBarController<UITabBarControllerDelegate>
@property (strong, nonatomic) IBOutlet UITabBar *tabBar;
@end
<强> CustomTabBarController.m 强>
- (void)viewDidLoad
{
CGRect tabBarFrame = self.tabBar.frame ;
tabBarFrame.origin.y -= kOrigin;
tabBarFrame.size.height = kTabBarHeight;
self.tabBar.frame = tabBarFrame;
self.tabBarController.delegate = self;
/* Tab Bar Background */
UIImage *tabBarBackgroundImage = [UIImage imageNamed:@"tabBarBackgroundImage.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackgroundImage];
/* Tab Bar Item */
UIButton *surveyButton = [UIButton buttonWithType:UIButtonTypeCustom];
[surveyButton addTarget:self action:@selector(surveyButtonDidSelect) forControlEvents:UIControlEventTouchUpInside];
surveyButton.tag = surveyButtonTag;
[surveyButton setBackgroundImage:[UIImage imageNamed:@"someimage.png"] forState:UIControlStateNormal];
CGRect surveyButtonFrame = surveyButton.frame ;
surveyButtonFrame.origin.x = /*Proper value in your case */;
surveyButtonFrame.origin.y = /*Proper value in your case */;
surveyButtonFrame.size.height = /*Proper value in your case */ ;
surveyButtonFrame.size.width =/*Proper value in your case */;
surveyButton.frame = surveyButtonFrame;
[self.tabBar addSubview:surveyButton];
UIButton *statusButton = [UIButton buttonWithType:UIButtonTypeCustom];
statusButton.tag = statusButtonTag;
[statusButton addTarget:self action:@selector(statusButtonDidSelect) forControlEvents:UIControlEventTouchUpInside];
[statusButton setBackgroundImage:[UIImage imageNamed:@"someimage.png"] forState:UIControlStateNormal];
CGRect statusButtonFrame = statusButton.frame ;
statusButtonFrame.origin.x = /*Proper value in your case */;
statusButtonFrame.origin.y = /*Proper value in your case */;
statusButtonFrame.size.height = /*Proper value in your case */;
statusButtonFrame.size.width = /*Proper value in your case */;
statusButton.frame = statusButtonFrame;
[self.tabBar addSubview:statusButton];
}
-(void)surveyButtonDidSelect
{
self.selectedIndex = 0 ;
}
-(void)statusButtonDidSelect
{
self.selectedIndex = 1;
}
它对我有用,我没有遇到任何问题。 希望,它有所帮助。
答案 1 :(得分:1)
要添加到@ limon的答案,如果你想改变自定义UITabBar的高度,我发现从另一个SO答案,抱歉不记得web链接引用,下面的代码做了诀窍并将其锁定在底部好吧,我在@ limon的代码中找到了UITabBar,并没有用他的代码开箱即用:
override func viewWillLayoutSubviews() {
//UITabBar Height
var tabFrame: CGRect = self.tabBar.frame
tabFrame.size.height = 75
tabFrame.origin.y = self.view.frame.size.height - 75
self.tabBar.frame = tabFrame
}
显然你想从limon的答案中删除类似的代码,或者可能将他的整个代码段移到viewWillLayoutSubviews
我没试过,我在我的viewDidLoad
答案 2 :(得分:0)
iPhone 5 / iPhone 4标签栏中图像的最大尺寸为96 x 64,因此您可以在某种程度上受限制,而无需自行滚动。虽然在您的示例图像中,这些可能符合约束条件。