关于UITabBarController显示,定义UITabBar的显示样式

为了解决:UITabBarController 显示不按照系统的样式走,按照自己的意愿来显示出来

步骤:

1:定义UITabBarController :

     UITabBarController *tabBarController = [[UITabBarController alloc]initWithNibName:nil bundle:nil];

     tabBarController.viewControllers = [[NSArray allocinitWithObjects:oneNav,twoNav,threeNav,fourNavnil];

     // 得到UITabBar

     UITabBar *tabBar = tabBarController.tabBar;

    // 得到每个UITabBarItem

    UITabBarItem *aTabBarItem = [tabBar.items objectAtIndex:0];

    UITabBarItem *bTabBarItem = [tabBar.items objectAtIndex:1];

    UITabBarItem *cTabBarItem = [tabBar.items objectAtIndex:2];

    UITabBarItem *dTabBarItem = [tabBar.items objectAtIndex:3];


    aTabBarItem.title = @"aaa";

    bTabBarItem.title = @"bbb";

    cTabBarItem.title = @"ccc";

    dTabBarItem.title = @"ddd";

    // 选中与不选中的小图片

    [aTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"tab_featured_seclected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_featured"]];

    [bTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"tab_free_seclected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_free"]];

    [cTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"tab_top_seclected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_top"]];

    [dTabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"tab_more_seclected"] withFinishedUnselectedImage:[UIImage imageNamed:@"tab_more"]];

   UIImage* tabBarBackground = [self scaleImage:[UIImage imageNamed:@"top_bg.png"]];

    // 修改UITabBar的背景颜色

    [[UITabBar appearance] setBackgroundImage:[tabBarBackground resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeStretch]];

    // 修改选中后的背景图

    [[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"btnadd3"]];

    // 字体的在正常情况下的显示颜色

    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:

                                                       [UIColor whiteColor], UITextAttributeTextColor,

                                                       nil] forState:UIControlStateNormal];

    

    // 字体在选中情况下的显示颜色

    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:

                                                       [UIColor blueColor], UITextAttributeTextColor,

                                                       nil] forState:UIControlStateSelected];




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值