After some research I found out (thanks to the following post) that in iOS 16 UITextView use Text Kit 2.
Unfortunately the new implementation has the issue described above, but it's possibile to force an UITextView to fallback to Text Kit 1 by accessing the layoutManager property (thanks to winshy for this solution).
So, in order to fix the issue you just need to add the following line:
_ = textView.layoutManager
The full code of the original example will become:
class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView! {
didSet {
_ = textView.layoutManager
var attributes = [NSAttributedString.Key: Any]()
let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 50
attributes[NSAttributedString.Key.paragraphStyle] = paragraphStyle
attributes[NSAttributedString.Key.font] = UIFont.preferredFont(forTextStyle: .body)
textView.typingAttributes = attributes
}
}
}
Topic:
UI Frameworks
SubTopic:
UIKit
Tags: