标签栏与大图标 [英] Tab Bar with Large Icons

查看:87
本文介绍了标签栏与大图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am wondering if there is a way to accomplish a tab bar with only large icons, I have attached an image below for reference. I am not interested in creating my own tab bar controller, and managing the view controllers myself.

推荐答案

这是我的解决方案,我创建了一个类, UITabBarController的子类

Here is my solution, i created a class which is a subclass of 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;
}

这对我有用,我没有遇到任何问题。
希望,它会有所帮助。

It's working for me,and i got no problem. Hope, it helps.

这篇关于标签栏与大图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆