2
我想改变我的UITabBarItem的背景颜色这样背景颜色:UITabBarItem - 在iOS版9
UITabBar.appearance().selectionIndicatorImage = UIImage.imageWithColor(UIColor.blackColor())
这里的extension
为UIImage
:
extension UIImage {
class func imageWithColor(color: UIColor) -> UIImage {
let rect = CGRectMake(0.0, 0.0, 1.0, 1.0)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
CGContextSetFillColorWithColor(context, color.CGColor)
CGContextFillRect(context, rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
为什么不使用UITabBar.appearance()。tintColor属性? –
我将色调设置为白色,并且我需要将背景色设置为黑色。查看更新的问题。 –
@NikitaZernov有关我的答案的任何更新? –