Created
April 1, 2021 15:22
-
-
Save DonMag/b0d839f5a4cffe4909a57541c9ee39d4 to your computer and use it in GitHub Desktop.
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
@IBDesignable | |
class IntrinsicHeightLabel: UILabel { | |
@IBInspectable | |
var h: CGFloat = 0 | |
override var intrinsicContentSize: CGSize { | |
let sz = super.intrinsicContentSize | |
if h == 0 { | |
return sz | |
} | |
return CGSize(width: sz.width, height: h) | |
} | |
override func layoutSubviews() { | |
numberOfLines = 0 | |
// show Intrinsic Height and Actual Height | |
text = "IH: \(intrinsicContentSize.height)\nAH:\(bounds.height)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment