2016-07-15 56 views
0

我在導航欄上找不到任何文字。有人知道怎麼做嗎?我已經設置了文本viewDidLoad中()swift - 如何調整導航欄文本中的字距?

self.navigationController?.navigationBar.topItem?.title = "My Nav Title" 
self.navigationController?.navigationBar.titleTextAttributes = [ NSFontAttributeName: UIFont(name: "Helvetica", size: 20)!, NSForegroundColorAttributeName: UIColor.whiteColor()] 

我看我們可以調整字距,但無法獲得此代碼工作

attributes: [NSKernAttributeName: 5.0] 

感謝多!

回答

0

我發現,從早期的修改後的代碼,現在可在Xcode 7.3.1

let titleLabel = UILabel() 

    let attributes: NSDictionary = [ 
     NSFontAttributeName:UIFont(name: "Helvetica", size: 20)!, 
     NSForegroundColorAttributeName:UIColor.blackColor(), 
     NSKernAttributeName:CGFloat(8.0) 
    ] 

    let attributedTitle = NSAttributedString(string: ""My Nav Title", attributes: attributes as? [String : AnyObject]) 

    titleLabel.attributedText = attributedTitle 
    titleLabel.sizeToFit() 
    self.navigationItem.titleView = titleLabel