I have a UITextView set to preview 4 lines of text, when the user clicks 'read more', the limit is set to 0 max lines and it displays at full length.
func showMore() {
self.readMoreLabel.snp.updateConstraints { (make) -> Void in
make.height.equalTo(0)
}
_descriptionHeight?.deactivate()
descriptionTextView.textContainer.maximumNumberOfLines = 0
descriptionTextView.invalidateIntrinsicContentSize()
}
This works fine, but in some instances there are less than or equal to 4 lines of text, so there is no need for a 'read more' button.
I cant see any way to calculate if the text is less than the 4 line limit to hide the read more
button. As the content size is forced by the line limit so i cant check that vs the frame height or similar standard methods.
Here is what i tried with no luck:
func setDescription(_ description: NSAttributedString) {
descriptionTextView.attributedText = description
setNeedsLayout()
layoutIfNeeded()
if descriptionTextView.contentSize.height < descriptionTextView.bounds.height {
self.readMoreLabel.snp.updateConstraints { (make) -> Void in
make.height.equalTo(0)
}
}
}
Can anyone advise how I can achieve a check that will be able to calculate if the content of the uitextview is less than 4 lines somehow?