ios tabtar 使用方法_iOS开发之TabBarController使用篇

1.代码创建TabBarController

demo演示

1.AppDelegate 设置和代码

AppDelegate

self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];

//创建并初始化UITabBarController

WBTabBarController *tabBarController = [[WBTabBarController alloc]init];

self.window.rootViewController = tabBarController;

self.window.backgroundColor = [UIColor whiteColor];

[self.window makeKeyAndVisible];

2.UITabBarController 设置和代码

UITabBarController

//初始化两个视图控制器

OneViewController *oneVc = [[OneViewController alloc]init];

TwoViewController *twoVc = [[TwoViewController alloc]init];

//为两个视图控制器添加导航栏控制器

UINavigationController *navOne = [[UINavigationController alloc]initWithRootViewController:oneVc];

UINavigationController *navTwo = [[UINavigationController alloc]initWithRootViewController:twoVc];

//设置控制器文字

navOne.title = @"首页";

navTwo.title = @"个人中心";

//设置控制器图片(使用imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal,不被系统渲染成蓝色)

navOne.tabBarItem.image = [[UIImage imageNamed:@"icon_home_bottom_statist"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

navOne.tabBarItem.selectedImage = [[UIImage imageNamed:@"icon_home_bottom_statist_hl"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

navTwo.tabBarItem.image = [[UIImage imageNamed:@"icon_home_bottom_search"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

navTwo.tabBarItem.selectedImage = [[UIImage imageNamed:@"icon_home_bottom_search_hl"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

//改变tabbarController 文字选中颜色(默认渲染为蓝色)

[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor lightGrayColor]} forState:UIControlStateNormal];

[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];

//创建一个数组包含四个导航栏控制器

NSArray *vcArry = [NSArray arrayWithObjects:navOne,navTwo,nil];

//将数组传给UITabBarController

self.viewControllers = vcArry;

3.tabBar的隐藏/显示 设置和代码

tabBar的隐藏式显示

-(void)btnClickMethod{

ThirdViewController *thirdVc = [[ThirdViewController alloc]init];

//跳转隐藏tabBar

self.hidesBottomBarWhenPushed = YES;

[self.navigationController pushViewController:thirdVc animated:YES];

//返回时候显示tabBar

self.hidesBottomBarWhenPushed = NO;

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值