JamesSeo
JamesSeo

Reputation: 3

swift - Can't find the numberOfLines attribute of UINavigationBar title text

I have used UINavigationBar.appearance() in swift. By using this, I have changed the backgroundColor and the textColor of UINavigationBarusing the below code.

However, I can't find the numberOfLinesattribute of the UINavigationBar title text. Any help on this is appreciated.

 var naviAppreance = UINavigationBar.appearance()
 naviAppreance.tintColor = uicolorFromHex(0xffffff)
 naviAppreance.barTintColor = uicolorFromHex(0x00cc66)
 naviAppreance.titleTextAttributes = [ NSForegroundColorAttributeName : UIColor.whiteColor()]

Upvotes: 0

Views: 237

Answers (1)

Shamsudheen TK
Shamsudheen TK

Reputation: 31311

You have to design a custom view with a label and assign it as the titleView of your UINavigationBar

Example Swift Code:

var titleLabel = UILabel(frame: CGRectMake(0, 0, 480, 44))
titleLabel.backgroundColor = UIColor.clearColor()
titleLabel.numberOfLines = 2
titleLabel.shadowColor = UIColor(white: 0.0, alpha: 0.5)
titleLabel.textAlignment = UITextAlignmentCenter
titleLabel.font = UIFont.boldSystemFontOfSize(12.0) 
titleLabel.textColor = UIColor.whiteColor()
titleLabel.text = "This is a\nmultiline string"
self.navigationItem.titleView = label

Upvotes: 2

Related Questions