設(shè)置tabbar背景為透明,我按照網(wǎng)上的設(shè)置backgroundcolor沒有達(dá)到我的效果
于是設(shè)置圖片:
繼承類UITabBarController的viewDidLoad() 中
self.tabBar.backgroundImage = imageWithColor(color: UIColor(red: 0, green: 0, blue: 0, alpha: 0.2))
在底下寫這個方法
func imageWithColor(color: UIColor) -> UIImage? {
let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
context?.setFillColor(color.cgColor)
context?.fill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
自定義文字選擇和未選中顏色:
自定義的UITabBarController 的viewDidLoad() 中
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor(red: 156/255.0, green: 179/255.0, blue: 184/255.0, alpha: 1.0)], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white], for: .selected)
設(shè)置圖片原本的顏色
自定義的UITabBarController
override func awakeFromNib() {
self.tabBar.items?.forEach({ (it) in
it.image = it.image?.withRenderingMode(.alwaysOriginal)
it.selectedImage = it.selectedImage?.withRenderingMode(.alwaysOriginal)
})
}