首页 > 其他 > 详细

storyboard-UITabBar选中时颜色

时间:2015-07-28 00:43:17      阅读:928      评论:0      收藏:0      [点我收藏+]

今日尝试用storyboard实现tabbar,发现一下问题:

1.在storyboard中设置tabbaritem选中时image无法显示;

2.tabbaritem选中状态默认背系统渲染为蓝色;

解决方法:

//设置Image按照图像原始样式渲染,也就是无系统渲染

UIImage *selectedImage = [[UIImage imageNamed:@"tabbar_home_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    self.tabBarController.tabBar.selectedItem.selectedImage = selectedImage;

但是tabbaritem的title,在选中状态下还是被渲染为系统颜色。需要在自定义tabbarcontroller中设置tabbaritem样式。设置title颜色。

+(void)initialize {

    UITabBarItem *tabBarItem = [UITabBarItem appearance];

    //设置tabbarItem的字体颜色 此属性在viewdidload中设置不起效果。

    [tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateSelected];

}

总结:

由于以前是代码实现tabbarcontroller,以前使用controller.tabBarItem.selectedImage 在storyboard中不起作用。设置title颜色也需要放到initialize中。

self.tabBar.tintColor = [UIColor greenColor];设置tabbar渲染颜色。如果选中状态title 与 image颜色一致,设置此属性比较方便。

storyboard-UITabBar选中时颜色

原文:http://www.cnblogs.com/fenghuangzhan/p/4681600.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!