I have a UILabel
inside a UIStackView
, and the stack view is inside another UIScrollView
, I'm using auto layout. The label has single line (ie. numberOfLines
equal to 1) and in a few cases I need to set it to multiline (ie. numberOfLines
equal to 0) with an animation that expands it.
func expand() {
label.numberOfLines = 0
}
when I click expand:
messageView.expand()
UIView.animate(withDuration: 0.3) {
self.layoutIfNeeded()
}
However, when it expands, the label's frame isn't updated and I have to scroll (the scroll view) to make it fully visible. What could be wrong?
Thanks!
Animation of UILabel
doesn't perform within
UIView.animate(withDuration:)
.
This should work:
UIView.transition(with: label, duration: 0.5, options: .transitionCrossDissolve, animations: {
self.label.numberOfLines = 0
})
You can experiment with options and execution block.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With