UINavigationBar.apperance()。titleTextAttributes在swift中不起作用

时间:2016-03-04 07:18:10

标签: ios swift

UINavigationBar.apperance()。titleTextAttributes无效。 Swift Code在下面。

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

    UINavigationBar.appearance().translucent = false
    UINavigationBar.appearance().barTintColor = UIColor.greenColor()
    UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName:UIColor.whiteColor()]

    return true
}

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

在Appdelegate didFinishLaunchingWithOptions方法

中添加以下代码
 let navFont = UIFont(name: "HelveticaNeue-Bold", size: 30.0)
 UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.blackColor(), NSAttributedStringKey.font: navFont!]