Skip to content

Instantly share code, notes, and snippets.

@DonMag
Created April 1, 2021 15:22
Show Gist options
  • Save DonMag/b0d839f5a4cffe4909a57541c9ee39d4 to your computer and use it in GitHub Desktop.
Save DonMag/b0d839f5a4cffe4909a57541c9ee39d4 to your computer and use it in GitHub Desktop.
@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