Reputation: 387
I use titleTextAttributes to set lineBreakmode in TruncatingMiddle.
But I fail to show me the title with linebreakmode.
What's wrong with me?
Thanks.
let paragraph = NSMutableParagraphStyle()
paragraph.lineBreakMode = .byTruncatingMiddle
self.navigationController?.navigationBar.titleTextAttributes = [
NSFontAttributeName: defaultTitleFont ?? "" ,
NSParagraphStyleAttributeName: paragraph ]
Upvotes: 1
Views: 573
Reputation: 1126
From your question, what i get is you want a multiline title in your navigation bar, to accomplish so, you can simply do the following:
let label = UILabel(frame: CGRect(x:0, y:0, width:400, height:50))
label.backgroundColor = .clear
label.numberOfLines = 2
label.font = UIFont.boldSystemFont(ofSize: 16.0)
label.textAlignment = .center
label.textColor = .black
label.text = "This is a\nmultiline string for the navBar"
self.navigationItem.titleView = label
I hope it will solve your issue.
Upvotes: 3