I created a UILabel and synced its font size with a seekbar and loaded my html formatted text onto the UILabel. Unfortunately, the format gets removed if I change the font size of my UILabel using seekbar.
I used this approach, from garie, that was answered from another thread
private func getHtmlLabel(text: String) -> UILabel {
    let label = UILabel()
    label.numberOfLines = 0
    label.lineBreakMode = .byWordWrapping
    label.attributedString = stringFromHtml(string: text)
    return label
}
private func stringFromHtml(string: String) -> NSAttributedString? {
    do {
        let data = string.data(using: String.Encoding.utf8, allowLossyConversion: true)
        if let d = data {
            let str = try NSAttributedString(data: d,
                                             options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
                                             documentAttributes: nil)
            return str
        }
    } catch {
    }
    return nil
}
Link: Swift: Display HTML data in a label or textView
Is there any approach I could use to retain the my html formatted text?
EDIT #1: This is how I resize my UILabel.
@IBOutlet weak var textLabel: UILabel!
@IBAction func resizeText(_ sender: UISlider) {
    textLabel.font = UIFont.systemFont(ofSize: CGFloat(sender.value) * 20.0)
}
The HTML data I'm passing onto my UILabel:
<html><body><b>hello world</b></body></html>
This is the formatted HTML data on UILabel:
After resizing the UILabel, it loses its format:
EDIT #2:
Tried Milan's answer but encountered an error. Unresolved identifier in NSAttributedStringKey
Here's my code:
import UIKit
class GalleryViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        textLabel.attributedText = stringFromHtml()
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    @IBOutlet weak var textLabel: UILabel!
    @IBAction func resizeText(_ sender: UISlider) {
        if let attributedText = textLabel.attributedText {
            let newAttributedText = NSMutableAttributedString(attributedString: attributedText)
            newAttributedText.setFontSize(newSize: CGFloat(sender.value) * 20.0)
            textLabel.attributedText = newAttributedText
        }
    }
    private func stringFromHtml() -> NSAttributedString? {
        do {
            let string = "<html><body><b>hello world</b></body></html>"
            let data = string.data(using: String.Encoding.utf8, allowLossyConversion: true)
            if let d = data {
                let str = try NSAttributedString(data: d,
                                                 options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
                                                 documentAttributes: nil)
                return str
            }
        } catch {
        }
        return nil
    }
}
extension NSMutableAttributedString {
    func setFontSize(newSize: CGFloat) {
        beginEditing()
        self.enumerateAttribute(NSAttributedStringKey.font, in: NSRange(location: 0, length: self.length)) { (value, range, stop) in
            if let f = value as? UIFont {
                let newFont = f.withSize(newSize)
                removeAttribute(NSAttributedStringKey.font, range: range)
                addAttribute(NSAttributedStringKey.font, value: newFont, range: range)
            }
        }
        endEditing()
    }
}


 
     
    