设置 tabBar 下面文字和图片颜色

设置 tabBar 下面文字和图片颜色

设置图片

1.统一设置

tabBarItem.image =  XXimage

2.显示为图片原样

**设置--图片渲染模式为origin**
        childViewController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)

设置文字和大小颜色

  • 可以定制每一个自控制器的颜色tabBarItem.setTitleTextAttributes–传入一个字典(里面设置文字颜色和大小)
childViewController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)

tabBar 下面文字与对应的导航栏 title 文字设置

  • 事例代码
        childViewController.title = title
        childViewController.navigationItem.title = title
        childViewController.tabBarItem.title = title
  • 如果用上面一句就会设置成统一的文字
  • 如果用下面两句,则可以实现 tabBar 文字与导航栏 title 不同

如果tabBar下面的 image 中包括文字,此时不需要 tabBar 显示文字

  • 此时问题就是— image 会整体上移动
    *解决方法:调整 image 位置
    设置图片的 imageInsets
        //tabBarItem的 Insets top向上稍微移动就好
        childViewController.tabBarItem.imageInsets = UIEdgeInsets(top: 5, left: 0, bottom: 0, right: 0)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章