2015-08-28 90 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)替換。