[ad_1]
I’m utilizing a tableView and with the tableView I’m utilizing a label and my requirement is to make the label auto-adjusting in line with the textual content. So I’m calculating dynamic peak for my label. It’s working fantastic initially however after scroll the peak of the label is diminished. I do not know why.
// to calculate dynamic peak of the label
func peak(constraintedWidth width: CGFloat, font: UIFont) -> CGFloat {
let label = UILabel(body: CGRect(x: 0, y: 0, width: width, peak: .greatestFiniteMagnitude))
label.numberOfLines = 0
label.lineBreakMode = .byWordWrapping
label.textual content = self
label.font = font
label.sizeToFit()
return label.body.peak
}
[ad_2]
