// // ViewController.swift // TestLayoutManager // // Created by Miro Markarian on 3/2/22. // import UIKit class ViewController: UIViewController { @IBOutlet weak var textView: UITextView! override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. let testString = "Lorem ipsum dolor sit" self.view.backgroundColor = .black self.textView.backgroundColor = .clear let attributedText = NSMutableAttributedString(string: testString) attributedText.addAttribute(.font, value: UIFont.systemFont(ofSize: 24, weight: .bold), range: NSRange(location: 0, length: testString.count)) attributedText.addAttribute(.foregroundColor, value: UIColor.red, range: NSRange(location: 0, length: testString.count)) attributedText.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: NSRange(location: 0, length: testString.count)) attributedText.addAttribute(.underlineColor, value: UIColor.white, range: NSRange(location: 0, length: testString.count)) textView.textContainer.replaceLayoutManager(CaptionTextLayoutManager()) textView.attributedText = attributedText } }