问题是我为 UINavigationBar 设置的颜色与我为图层设置的相同颜色不同。我希望它是一样的! :)(见图)
AppDelegate.swift
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().setBackgroundImage(UIImage.imageWithColor(primaryColor), forBarMetrics: .Default)
UINavigationBar.appearance().barTintColor = primaryColor
UINavigationBar.appearance().tintColor = UIColor.whiteColor()
UINavigationBar.appearance().titleTextAttributes = [NSFontAttributeName: UIFont.systemFontOfSize(17), NSForegroundColorAttributeName:UIColor.whiteColor()]
viewDidLoad() 中的 MyController.swift
view.backgroundColor = primaryColor
扩展.swift
let primaryColor = UIColor(red: 132/255, green: 205/255, blue: 93/255, alpha: 1)
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
}
}
我认为问题出在 UIImage 扩展中。请帮我解决这个问题。
已解决
UINavigationBar.appearance().translucent = false
最佳答案
只需取消选中
Navigation Bar
的Translucent
属性。它对我有用。
关于ios - Swift UINavigationBar 背景颜色与主要颜色不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35300766/