【问题标题】:Swift UINavigationBar background color is different from main oneSwift UINavigationBar 背景颜色与主颜色不同
【发布时间】:2016-02-09 19:39:18
【问题描述】:

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

Extensions.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

【问题讨论】:

  • 我认为它是导航栏的半透明属性,它可以做到这一点!
  • @Mr.T 我打算提出同样的建议。试试看。
  • @Mr.T 谢谢 UINavigationBar.appearance().translucent = false 解决问题
  • 谢谢!在 swift 4 中:navigationController?.navigationBar.isTranslucent = false

标签: ios swift uinavigationbar


【解决方案1】:

只是uncheckTranslucent 属性Navigation Bar。它对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多