Created
July 17, 2015 18:12
-
-
Save isoiphone/ae86813a8e8c1e3ac1da to your computer and use it in GitHub Desktop.
because ... :(
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// based on: http://stackoverflow.com/questions/18118021/how-to-resize-superview-to-fit-all-subviews-with-autolayout | |
// required so we can have multiline labels properly resize their height based on content | |
class MultilineLabel: UILabel { | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
if numberOfLines == 0 && preferredMaxLayoutWidth != CGRectGetWidth(frame) { | |
preferredMaxLayoutWidth = frame.size.width | |
setNeedsUpdateConstraints() | |
} | |
} | |
override func intrinsicContentSize() -> CGSize { | |
var s = super.intrinsicContentSize() | |
if numberOfLines == 0 { | |
// found out that sometimes intrinsicContentSize is 1pt too short! | |
s.height += 1 | |
} | |
return s | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment