Skip to content

Instantly share code, notes, and snippets.

@pawankmrai
Created June 21, 2016 11:44
Show Gist options
  • Select an option

  • Save pawankmrai/32ef4c5691e22b88792e98ff38e6080f to your computer and use it in GitHub Desktop.

Select an option

Save pawankmrai/32ef4c5691e22b88792e98ff38e6080f to your computer and use it in GitHub Desktop.
UILabels and Auto Layout have a problem, because there aren't enough conditions to solve the layout uniquely.
The number of lines in a label is affected by its width, which in turn is affected by the number of lines etc...
To get a label to play nicely, you need to ensure it has a defined width,
it has its number of lines set to 0 and you might need to create a subclass that includes the following:
class MultilineLabelThatWorks : UILabel {
override func layoutSubviews() {
super.layoutSubviews()
preferredMaxLayoutWidth = bounds.width
super.layoutSubviews()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment