• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
梦幻仙境的精灵
博客园    首页    新随笔    联系   管理    订阅  订阅

IOS 改变tabbar的样式

1、改变默认的背景(背景色)
[[UITabBar appearance] setBackgroundImage:[UIImage imageFromColor:[UIColor colorWithR:50 G:66 B:81] forSize:CGSizeMake(SCREEN_WIDTH, MAIN_TABBAR_HEIGHT) withCornerRadius:0]];

2、改变选中的背景(背景色)

 

[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageFromColor:[UIColor colorWithRed:49/255.0 green:158/255.0 blue:141/255.0 alpha:1] forSize:CGSizeMake(SCREEN_WIDTH / 4, MAIN_TABBAR_HEIGHT) withCornerRadius:0]];

 

3、改变默认的图片的前景色

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

    注:此方法会导致所有颜色,或者说所有非透明的地方都变成设置的颜色。

    而当设置tabbaritem的image选项的时候,如果使用 

controller.tabbaritem.image = [[UIImage imageNamed:@"tabbar_item_group"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]

  这样的话,setTintColor 是不起作用的。

4、设置选中的图片的前景色

[[UITabBar appearance] setSelectedImageTintColor:MAIN_COLOR];

  注:此方法会导致所有颜色,或者说所有非透明的地方都变成设置的颜色。

      而当设置tabbaritem的selectedimage选项的时候,如果使用 

controller.tabbaritem.selectedimage = [[UIImage imageNamed:@"tabbar_item_group"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]

  这样的话,setSelectedImageTintColor 是不起作用的。

5、设置tabbar字体的颜色

 //设置默认时的字体颜色
[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal]; //设置选中时的字体颜色 [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:MAIN_COLOR, NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];

  同理,这里修改  NSForegroundColorAttributeName  为 NSFontAttributeName、NSUnderlineStyleAttributeName等,可以修改这些字体不同的属性。

posted @ 2016-05-05 15:48  梦幻仙境的精灵  阅读(1090)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3