UINavigationBar.appearance()不接受RGB或HUE定义的UIColor

时间:2015-07-03 09:27:06

标签: swift uinavigationbar

我正在尝试更改导航栏颜色。我在stackoverflow上尝试了很多方法,但没有一个接受UIColor作为RGB或HUE。

AppDelegate上的以下代码可以在一定程度上更改颜色。

但由于某种原因,它只接受预定义的颜色

UIColor(red: 206, green: 50, blue: 34, alpha: 1)

虽然我需要RGB定义的更具体的颜色,如:

  @UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?


    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {


        // CHANGE NAV BAR COLOUR **********************************************

        var navigationBarAppearace = UINavigationBar.appearance()

        //changes content color
        navigationBarAppearace.tintColor = UIColor.whiteColor()

        //changes bar color

        //WORKS FINE
        navigationBarAppearace.barTintColor =  UIColor.blackColor()

        //DO NOT WORK
//        navigationBarAppearace.barTintColor =  UIColor(hue: 203, saturation: 31, brightness: 44, alpha: 1)
//        navigationBarAppearace.barTintColor = UIColor(red: 206, green: 50, blue: 34, alpha: 1)


        // Override point for customization after application launch.

        return true
    }

以下是我正在使用的代码

{{1}}

1 个答案:

答案 0 :(得分:0)

只需将其除以255

navigationBarAppearace.barTintColor = UIColor(red: 206/255.0, green: 50/255.0, blue: 34/255.0, alpha: 1.0)