ios - Swift UINavigationBar 背景颜色与主要颜色不同

标签 ios swift uinavigationbar

问题是我为 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
    }
}

enter image description here

我认为问题出在 UIImage 扩展中。请帮我解决这个问题。

已解决

UINavigationBar.appearance().translucent = false

最佳答案

只需取消选中 Navigation BarTranslucent 属性。它对我有用。

关于ios - Swift UINavigationBar 背景颜色与主要颜色不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35300766/

相关文章:

ios - 用于固定 UILabel 高度的字符串

swift - DispatchGroup().wait() 之后的代码从未调用

html - 下划线/边框间距 - 设置特定宽度

iphone - 我的导航 Controller 需要在 iOS5 中按两次后退?

ios - 在 viewDidLoad 期间设置的导航栏按钮在 iOS 11 中出现 View 之后才会出现

ios - 将完成处理程序池在一起,以便在执行多个闭包后方法完成

ios - 如何在 IOS 的 webview 中检查响应类型(Json/Html)

ios - 为什么double类型的主窗口是可选的?

iOS - 如何使用 Swift 在 UITableview 中以矩阵格式(行和列)显示值

ios - 如何关闭 UINavigationBar 的大标题?