1

我想知道是否有一种方法可以完成只有大图标的标签栏,我在下面附上了一张图片以供参考。我对创建自己的标签栏控制器和自己管理视图控制器不感兴趣。

在此处输入图像描述

4

3 回答 3

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;
}

它对我有用,我没有问题。希望能帮助到你。

于 2013-05-24T19:10:36.977 回答
1

要添加到@limon 的答案,如果您想更改自定义 UITabBar 的高度,我从另一个 SO 答案中找到,抱歉不记得网络链接参考,下面的代码起到了作用并将其锁定在底部,其中我发现使用@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

于 2017-03-21T04:32:24.530 回答
0

iPhone 5/iPhone 4 的标签栏中图像的最大尺寸为 96 x 64,因此您在此范围内会受到一定程度的限制,而无需自行滚动。尽管在您的示例图像中,这些可能符合约束条件。

于 2013-05-24T18:30:10.187 回答