I have a text label containing dynamic text inside of a scrollview. A few lines of text are being cut off from the bottom of the label. I've set everything up in Storyboard using auto layout.
I've tried toggling isScrollingEnabled in ViewDidLoad on the UIScrollView per another post to no avail.
I've also tried removing the bottom constraint on the text label and padding it
I've narrowed down the issue by process of elimination to an extension I'm using to change the font in the HTML as I'm working with an html attributed string. I can't figure out why this is cutting the text off, sometimes just a couple lines, sometimes the majority of the content, and sometimes all of the content is missing
extension NSAttributedString {
func changeHTMLFont(_ text: NSAttributedString) -> NSAttributedString {
let newAttributedString = NSMutableAttributedString(attributedString: (text))
newAttributedString.enumerateAttribute(NSAttributedStringKey.font, in: NSMakeRange(0, newAttributedString.length), options: []) { value, range, stop in
guard let currentFont = value as? UIFont else {
return
}
//USE FOR FACE OPTIONS
let fontDescriptor = currentFont.fontDescriptor.addingAttributes([UIFontDescriptor.AttributeName.family: "Optima", UIFontDescriptor.AttributeName.face: "Bold"])
//let fontDescriptor = currentFont.fontDescriptor.addingAttributes([UIFontDescriptorFamilyAttribute: "Optima"])
if let newFontDescriptor = fontDescriptor.matchingFontDescriptors(withMandatoryKeys: [UIFontDescriptor.AttributeName.family]).first {
let newFont = UIFont(descriptor: newFontDescriptor, size: 32.0) //use size: currentFont.pointSize for default font size
newAttributedString.addAttributes([NSAttributedStringKey.font: newFont], range: range)
}
}
return newAttributedString
}
}
Storyboard Hierarchy:
UITextLabel Constraints (Superview being the UIScrollView):
UPDATED IMAGES:
View of screen before scrolling:
View of screen when reaching bottom of label: