1. 设置透明背景
tabBar.backgroundImage = UIImage()
2. 阻止系统渲染 tabBar.image
UITabBarItem 初始化方法init(title:image:selectedImage:)
中有说明
By default, the actual unselected and selected images are automatically created from the alpha values in the source images. To prevent system coloring, provide images with
UIImage.RenderingMode.alwaysOriginal
.
因此如果想要阻止系统渲染 tabBar 图片,需要使用UIImage(named: "ta bImageName")?.withRenderingMode(.alwaysOriginal)
的方式设置图片
3. tintColor 与 barTintColor
tintColor 可设置 tabBar title 颜色,barTintColor 设置 tabBar 背景色,如果想要在设置 tintColor 时不影响 tabBar 的标题,可使用
tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.init(rgb: 0x26000000),NSAttributedString.Key.font: font], for: .normal)
tabBarItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor: UIColor.white : UIColor.init(rgb: 0xFF9064E4),NSAttributedString.Key.font: font], for: .selected)
网友评论