I've some UITextView
declared as the following
lazy var inputTextView: UITextView = {
let tv = UITextView()
tv.tintColor = UIColor.darkGray
tv.font = UIFont.systemFont(ofSize: 17)
tv.backgroundColor = UIColor.white
return tv
}()
I've been searching how can I predefine the line height for this UITextView
so whenever I write a long text, when it reaches the end of the line and goes to the following line, the spacing would be bigger than the default.
I've tried using the following inside the UITextView
declaration:
let style = NSMutableParagraphStyle()
style.lineSpacing = 40
let attributes = [NSParagraphStyleAttributeName : style]
tv.attributedText = NSAttributedString(string: "", attributes:attributes)
Which would become:
lazy var inputTextView: UITextView = {
let tv = UITextView()
tv.tintColor = UIColor.darkGray
tv.font = UIFont.systemFont(ofSize: 17)
tv.backgroundColor = UIColor.white
let style = NSMutableParagraphStyle()
style.lineSpacing = 40
let attributes = [NSParagraphStyleAttributeName : style]
tv.attributedText = NSAttributedString(string: "", attributes:attributes)
return tv
}()
It only works if I pre-insert some text in the attributedText
property but since the text is empty in the beginning it will not use those properties and it will be set as default.
How can I increase the default line height and keep it whenever I'm writing in the UITextView
?
Thanks ;)