标签栏与大型图标

我想知道是否有一种方法来完成一个标签栏只有大图标,我已附上一张图片以供参考。 我不想创build自己的标签栏控制器,并自己pipe理视图控制器。

在这里输入图像说明

这是我的解决scheme,我创build了一个类,它是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; } 

它为我工作,我没有问题。 希望能帮助到你。

iPhone 5 / iPhone 4上的标签栏中图像的最大尺寸为96 x 64,因此您在某种程度上受到限制,无法自行滚动。 尽pipe在你的示例图像中可能适合约束条件。

要添加到@ limon的答案,如果你想改变自定义UITabBar的高度,我发现从另一个SO答案,抱歉不记得networking链接引用,下面的代码做了把戏,并locking在底部,以及我发现与@ 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调用他的代码