2017-02-22 65 views
0

我在我的视图背景和导航栏上设置了相同的颜色。但是当我运行代码时,颜色是不同的。不知道发生了什么。有人可以帮助我吗? :|将相同颜色设置为导航栏和视图,但在运行时获得不同颜色

self.navigationController?.navigationBar.barTintColor = Utils.Color.bgColor 
view.backgroundColor = Utils.Color.bgColor 

// some trys to fix the problem... 
self.navigationController?.navigationBar.shadowImage = UIImage() 
self.navigationController?.navigationBar.isTranslucent = false 
self.navigationController?.navigationBar.backgroundColor = Utils.Color.bgColor 
self.navigationController?.navigationBar.isOpaque = false 

enter image description here

回答

0

这是我使用,注意底色是不同的,我比较喜欢白色/黄色文字:

在AppDelegate中:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 
    UINavigationBar.appearance().barTintColor = UIColorFromRGB(0x112A0F) //my green 
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white] 
    UINavigationBar.appearance().tintColor = UIColor.yellow 
    UINavigationBar.appearance().isTranslucent = false 
    return true 
} 

的Someplace accessable (对我来说这是一个框架,因为我在其他地方使用它:

public func UIColorFromRGB(_ rgbValue: UInt) -> UIColor { 
    return UIColor(
     red: CGFloat((rgbValue & 0xFF0000) >> 16)/255.0, 
     green: CGFloat((rgbValue & 0x00FF00) >> 8)/255.0, 
     blue: CGFloat(rgbValue & 0x0000FF)/255.0, 
     alpha: CGFloat(1.0) 
    ) 
} 

是的,你可以在AppDelegate使用UIColorFromRGB。我看到的最大差异是你包括'isOpaque。尝试先删除。

相关问题