uitabaritem-iOS 9中的背景色
我正试图通过以下方式更改UITabBarItem的背景色:uitabaritem-iOS 9中的背景色,ios,swift,uitabbar,uitabbaritem,ios9,Ios,Swift,Uitabbar,Uitabbaritem,Ios9,我正试图通过以下方式更改UITabBarItem的背景色: UITabBar.appearance().selectionIndicatorImage = UIImage.imageWithColor(UIColor.blackColor()) 以下是UIImage的扩展: extension UIImage { class func imageWithColor(color: UIColor) -> UIImage { let rect = CGRectMake
UITabBar.appearance().selectionIndicatorImage = UIImage.imageWithColor(UIColor.blackColor())
以下是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
}
}
它不起作用。下面是它的最终外观:看起来您的图像太小了让rect=CGRectMake(0.0,0.0,1.0,1.0)
。尝试替换为let rect=CGRectMake(0.0,0.0,50.0,50.0)
为什么不使用uitabar.appearance().tintColor属性呢?我正在将“淡色”设置为白色,需要将“背景色”设置为黑色。查看更新的问题。@NikitaZernov关于我的答案有任何更新吗?