2016-03-04 99 views
1

UINavigationBar.apperance()。titleTextAttributes不起作用。 Swift代码如下。UINavigationBar.apperance()。titleTextAttributes在swift中不起作用

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

这是否帮助? http://stackoverflow.com/a/18937321/646960 –

+0

让属性:字典= [NSFontAttributeName:UIFont.systemFontOfSize(19.0),NSForegroundColorAttributeName:UIColor.whiteColor()]。 UIBarButtonItem.appearance()setTitleTextAttributes(属性,forState :UIControlState.Normal) – SARANGA

+0

@LoïsDiQual谢谢 – SARANGA

回答

0

添加以下代码的appdelegate didFinishLaunchingWithOptions方法

let navFont = UIFont(name: "HelveticaNeue-Bold", size: 30.0) 
UINavigationBar.appearance().titleTextAttributes = [NSAttributedStringKey.foregroundColor : UIColor.blackColor(), NSAttributedStringKey.font: navFont!]