Skip to content

Instantly share code, notes, and snippets.

@grzegorzkrukowski
Created May 17, 2017 15:43
Show Gist options
  • Save grzegorzkrukowski/e1fd29f6bccfd85679b78130ec106a56 to your computer and use it in GitHub Desktop.
Save grzegorzkrukowski/e1fd29f6bccfd85679b78130ec106a56 to your computer and use it in GitHub Desktop.
Fixing problem of using Label with autosizing cells
class UILabelPreferedWidth : UILabel {
override var bounds: CGRect {
didSet {
if (bounds.size.width != oldValue.size.width) {
self.setNeedsUpdateConstraints()
}
}
}
override func updateConstraints() {
if(preferredMaxLayoutWidth != bounds.size.width) {
preferredMaxLayoutWidth = bounds.size.width
}
super.updateConstraints()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment