-2

I would like to customize my navigation title but run into a problem. "String is not identical to NSObject". Can someone point me in the right direction? My code is below,

let font = UIFont(name: "HelveticaNeue", size: 15.0)
let textFont = [NSFontAttributeName: font]
let navText = [NSAttributedString(string: "MY STRING HERE", attributes: textFont)]

var navString = UILabel()
navString.appendAttributedString(navText)
self.navigationItem.titleView = navString

UPDATE: I was able to solve the problem with the following code,

    var navString: NSString = "MY STRING HERE"
    var completedNavString = NSMutableAttributedString()

    completedNavString = NSMutableAttributedString(string: navString as String, attributes: [NSFontAttributeName:UIFont(name: "Georgia", size: 18.0)!])

    var navLabel = UILabel()
    navLabel.attributedText = completedNavString
    navLabel.sizeToFit()
    self.navigationItem.titleView = navLabel
Jaxs_ios
  • 48
  • 10

1 Answers1

0
var navString = UILabel()
navString.appendAttributedString(navText)

You can't "append" anything to a UILabel. Try navString.attributedText = navText.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thanks, that was helpful. Im still getting the error message for "let navText = [NSAttributedString(string: "MY STRING HERE", attributes: textFont)]" – Jaxs_ios May 06 '15 at 00:36
  • Remove the square brackets. This is Swift, not Objective-C! – matt May 06 '15 at 00:40