1

I've put a UILabel in my notification content extension storyboard and set it up using auto layout. I've also set the numberOfLines to 0. In the storyboard, it looks perfectly fine but when I use it on my device, the label is coming out to be a single line. Am I missing anything?

Edit (ScreenShots added):

enter image description here

enter image description here

Also, when a new notification comes, I see a blank info and it's updated after a few secs.

enter image description here

More ScreenShots Added:

Number of lines is set to 0.

and in the code I'm setting it like this:

titleString.text = "Saturday SuperBowl Saturday SuperBowl Saturday SuperBowl"

But still it is coming as a single line.

enter image description here

Bhavuk Jain
  • 1,917
  • 1
  • 12
  • 23

1 Answers1

1

You must set the uilabels preferredMaxLayoutWidth. You can do this in your view controller:

override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    titleString.preferredMaxLayoutWidth = titleString.frame.size.width
    self.view.layoutIfNeeded()
}

or subclassing your uilabel:

override func layoutSubviews() {
    self.preferredMaxLayoutWidth = self.frame.size.width
    super.layoutSubviews
}
Robert Erdei
  • 11
  • 1
  • 4