美文网首页
UITabBarController的一些心得

UITabBarController的一些心得

作者: 向晚forever | 来源:发表于2017-02-09 15:31 被阅读11次
//设置tabbar的图片和文字(但是图片显示为系统默认颜色,不会渲染为图片本身颜色)
vc.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"title" image:[UIImage imageNamed:icon] selectedImage:[UIImage imageNamed:sIcon]];
//设置选中状态图片和文字颜色
[[UITabBar appearance] setTintColor:self.baseColor];

下面这个方法是渲染图片本身颜色,且改变文字的size和font(选中和非选中状态都是可以设置的)

  vc.navigationItem.title = title;
  //特别注意这个title,有一次没有赋值文字一直不出来。
  vc.title = title;
  vc.tabBarItem.image = [[UIImage imageNamed:icon]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];;
  vc.tabBarItem.selectedImage = [[UIImage imageNamed:sIcon]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// 设置文字的样式
NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
        selectTextAttrs[NSForegroundColorAttributeName] = [AppContext sharedAppContext].baseColor;
[vc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];

相关文章

网友评论

      本文标题:UITabBarController的一些心得

      本文链接:https://www.haomeiwen.com/subject/wgaiittx.html