2015-08-28 92 views
2

我想改变我的UITabBarItem的背景颜色这样背景颜色:UITabBarItem - 在iOS版9

UITabBar.appearance().selectionIndicatorImage = UIImage.imageWithColor(UIColor.blackColor()) 

这里的extensionUIImage

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 
    } 
} 

它不工作。以下是它最终的样子:enter image description here

+0

为什么不使用UITabBar.appearance()。tintColor属性? –

+0

我将色调设置为白色,并且我需要将背景色设置为黑色。查看更新的问题。 –

+0

@NikitaZernov有关我的答案的任何更新? –

回答

1

看起来你的图片太小了let rect = CGRectMake(0.0, 0.0, 1.0, 1.0)。尝试用let rect = CGRectMake(0.0, 0.0, 50.0, 50.0)替换。