IOS学习(七)UITabBarViewController标签视图控制器

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    [self setWindow:[[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]];
    [self.window makeKeyAndVisible];
    
    UITabBarController *tabBarController = [[UITabBarController alloc] init];
    tabBarController.tabBar.backgroundColor = [UIColor yellowColor];
    [self.window setRootViewController:tabBarController];
    
    FirstViewController *firstVc = [[FirstViewController alloc] init];
    firstVc.tabBarItem.title = @"首页";
    firstVc.tabBarItem.image = [UIImage imageNamed:@"nav_icon_article_f"];
    firstVc.tabBarItem.selectedImage = [UIImage imageNamed:@"nav_icon_article_p"];
    UINavigationController *firstNc = [[UINavigationController alloc] initWithRootViewController:firstVc];
    
    SecondViewController *second = [[SecondViewController alloc] init];
    second.tabBarItem.title = @"选车";
    second.tabBarItem.image = [[UIImage imageNamed:@"nav_icon_findcar_f"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    second.tabBarItem.selectedImage = [UIImage imageNamed:@"nav_icon_findcar_p"];
    UINavigationController *secondNc = [[UINavigationController alloc] initWithRootViewController:second];
    
    ThirdViewController *third = [[ThirdViewController alloc] init];
    third.tabBarItem.title = @"选车";
    third.tabBarItem.image = [UIImage imageNamed:@"nav_icon_forum_f"];
    third.tabBarItem.selectedImage = [UIImage imageNamed:@"nav_icon_forum_p"];
    UINavigationController *thirdNc = [[UINavigationController alloc]initWithRootViewController:third];

//设置tabbar的背景色
UIView *backView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 49)];
    backView.backgroundColor = [UIColor whiteColor];
    [self.tabBar insertSubview:backView atIndex:0];

 

@implementation FirstViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"首页";
    self.view.backgroundColor = [UIColor greenColor];
    
    UIBarButtonItem *barButtom = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(hahh)];
    self.navigationItem.rightBarButtonItem = barButtom;
}

- (void)hahh {
    
    ForthViewController *forth = [[ForthViewController alloc] init];
    //隐藏tabbar,跳转之前,由目标试图控制来设置这个参数
    [forth setHidesBottomBarWhenPushed:true];
    [self.navigationController pushViewController:forth animated:YES];
}

//设置选中、未选中的图标
    //UIImageRenderingModeAlwaysOriginal 去掉系统默认的蓝色处理
    childVc.tabBarItem.image = [[UIImage imageNamed:imageNmae] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //设置选中、未选中的字体颜色
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor blackColor]} forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值