UITabBarController的使用

UITabBarController 是多页面视图控制器切换控制器

一、主要使用方法,即属性设置:

1、视图控制器集合:viewControllers

2、切换视图属性:tabbar

2-1、tabbar背景颜色:backgroundColor

2-2、tabbar背景图标:backgroundImage

2-3、tabbar标题(选中,或非选中状态):UITabBarItem,- (void)setTitleTextAttributes:(nullable NSDictionary<NSString *,id> *)attributes forState:(UIControlState)state

2-4、tabbar图标(选中,或非选中状态):UITabBarItem,- (void)setFinishedSelectedImage:(nullable UIImage *)selectedImage withFinishedUnselectedImage:(nullable UIImage *)unselectedImage

或进行 2-3、2-4属性的统一设置方法如:

 

// 设置标题,未选中状态图标,选中状态图标
UITabBarItem *barItem = [[UITabBarItem alloc] initWithTitle:title image:imageNormal selectedImage:imageSelected];
xxxViewController.tabBarItem = barItem;
// 设置标题字体颜色
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blackColor]} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor orangeColor]} forState:UIControlStateSelected];
// 设置标题字体大小
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:8.0]} forState:UIControlStateNormal];
// 设置标题字体偏移
[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0.0, -8.0)];
// 设置图标选中时颜色
[[UITabBar appearance] setTintColor:[UIColor redColor]];

 

3、默认选中视图控制器:selectedIndex

     

二、使用注意事项:

1、设置视图控制器集合时,是 UINavigationController导航栏控制器集合;

2、设置视图控制器集合时,通常小于等于 5个视图控制器,超过 5个时系统默认生成一个 more的控制器页面,用于操作多余的视图控制器

3、视图控制器导航栏标题设置时,注意使用:" self.navigationItem.title = @"xxx"; ",而不使用" self.title = @"xxx"; ",避免影响 UITabBarController中 tabbar标题的设置。

4、当要显示下一个视图控制器,且需要隐藏 tabbarController控制器时,设置视图控制器的属性 hidesBottomBarWhenPushed值为YES,如:

 

UIViewController *nextVC = [[UIViewController alloc] init];
nextVC.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:nextVC animated:YES];

 

5、第一次初始化时,会出现设置的 tabbar图标颜色异常,设置属性 tintColor与图标颜色一致后,则不会,如:

 

[[UITabBar appearance] setTintColor:[UIColor redColor]];

 

6、tabbar标题设置后出现偏移情况,即靠近底端,可通过设置属性 titlePositionAdjustment进行调整,如:

 

[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0.0, -8.0)];

 

7、设置 badgeValue标识属性时,特别是在 viewController中设置时,注意使用方法为" self.navigationController.tabBarItem.badgeValue = @"0"; ",而不是" self.tabBarItem.badgeValue = @"0"; ",否则无效,如:


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

番薯大佬

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值