Browse Questions
- intrinsicContentSize is the natural size a view prefers based on its content — like a label fitting its text, or a button fitting its title.
- UIViewPropertyAnimator is an object that owns an animation, which makes that animation interruptible, reversible, and scrubbable.
- Themis exposes Secure Cell for encrypting data at rest, Secure Message for encrypting or signing individual payloads between two parties, Secure Session for an encrypted stateful channel over an…
- multipart/form-data is a content type used to send mixed data — like a file and text fields together — in a single request.
Answer:
intrinsicContentSize is the natural size a view prefers based on its content — like a label fitting its text, or a button fitting its title. Auto Layout uses this when no explicit size constraint is set.
Code Example:
// UILabel and UIButton have intrinsicContentSize automatically
let label = UILabel()
label.text = "Hello"
print(label.intrinsicContentSize) // e.g. (33.0, 20.5)
// Custom view — override to declare your preferred size
class BadgeView: UIView {
var count: Int = 0 {
didSet { invalidateIntrinsicContentSize() } // tell Auto Layout size changed
}
override var intrinsicContentSize: CGSize {
let size = max(24, CGFloat(count) * 10)
return CGSize(width: size, height: 24)
}
}
// Return this to say "I have no opinion on this dimension"
return CGSize(width: UIView.noIntrinsicMetric, height: 44)