iOS开发-tabBar的常见设置

效果展示

1. 签tarBar协议
 目的点击时tabBarItem.badgeValue = nil
<UITabBarControllerDelegate>
2.设置
 self.window= [[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]];
   self.window.backgroundColor= [UIColorwhiteColor];
    [
self.windowmakeKeyAndVisible];
   
   // 微信部分 
   RootViewController*rootVC = [[RootViewControlleralloc]init];
   
UINavigationController *naVC = [[UINavigationControlleralloc]initWithRootViewController:rootVC];
   
// 设置内容
    naVC.
tabBarItem= [[UITabBarItemalloc]initWithTitle:@"微信"image:[UIImageimageNamed:@"clock"]tag:1000];
   
// 提示信息
    naVC.
tabBarItem.badgeValue= @"1";
   
   
   // 通讯录部分 
   firstViewController*firstVC = [[firstViewControlleralloc]init];
   
UINavigationController *firstnaVC = [[UINavigationControlleralloc]initWithRootViewController:firstVC];
    firstnaVC.
tabBarItem= [[UITabBarItemalloc]initWithTitle:@"通讯录"image:[UIImageimageNamed:@"chat2"]selectedImage:[UIImageimageNamed:@"gear"]];
    firstnaVC.
tabBarItem.badgeValue= @"new";
   
   
   // 第三部分 
   SecondViewController*secondVC = [[SecondViewControlleralloc]init];
   
UINavigationController *secondnaVC = [[UINavigationControlleralloc]initWithRootViewController:secondVC];
    secondVC.
tabBarItem= [[UITabBarItemalloc]initWithTabBarSystemItem:UITabBarSystemItemBookmarkstag:10000];
    secondVC.
tabBarItem.badgeValue= @"99+";
   
   
   
   
// 标签视图控制器,用来管理导航控制器的
   
UITabBarController *tabBars = [[UITabBarControlleralloc]init];
   
   
// 设置背景颜色
    tabBars.
tabBar.barTintColor= [UIColorgreenColor];
   
// 设置不半透明
    tabBars.
tabBar.translucent= NO;
   
// 设置选中按钮的颜色
    tabBars.
tabBar.tintColor= [UIColorblueColor];
   
   
   
   
// 给标签控制器指定子控制器
    tabBars.
viewControllers= [NSArrayarrayWithObjects:naVC,firstnaVC,secondnaVC,nil];
   
self.window.rootViewController= tabBars;
    [tabBars
release];
   
   
    tabBars.delegate= self;

   
3.实现tarBar协议方法
//点击tabBar上按钮时触发
- (
void)tabBarController:(UITabBarController*)tabBarController didSelectViewController:(UIViewController*)viewController{
   
NSLog(@"==%@",viewController);
   
UINavigationController*navc = (UINavigationController*)viewController;
    navc.
tabBarItem.badgeValue= nil;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值