I have a problem with adding Read More/Less text in paragraph. That text needs in iPod but no need for iPad. Please view the attached image below.
The first problem is that before I clicking "Read More" button, there is a space at the top left corner. When I click on Read More button, the label is goes to top and there is no space.
The second problem is that Read More button does not require if the device is iPad because the screen size is big and all the texts are show.
For iPod, it needs to have that button.
Here is my code.
func getLabelHeight(text: String, width: CGFloat, font: UIFont) -> CGFloat {
let lbl = UILabel(frame: .zero)
lbl.frame.size.width = width
lbl.font = font
lbl.numberOfLines = 0
lbl.text = text
lbl.sizeToFit()
return lbl.frame.size.height
}
@IBAction func btnReadMore(_ sender: Any) {
if isLabelAtMaxHeight {
btnReadmore.setTitle("Read more", for: .normal)
isLabelAtMaxHeight = false
lblReviewHeight.constant = 93
}
else {
btnReadmore.setTitle("Read less", for: .normal)
isLabelAtMaxHeight = true
lblReviewHeight.constant = getLabelHeight(text: lblReview.text!, width: view.bounds.width, font: lblReview.font)
}
}
How can I check this when Read button is require or not? Please help me. I don't want to add any other library file.