設置 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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章