无法在UITextView中应用行距? [英] Can't apply line spacing with UITextView?
本文介绍了无法在UITextView中应用行距?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您对UITextView的行距有任何想法吗?我无法应用.下面是我的代码.
Do you have any ideas about line spacing with UITextView? I cannot apply it. Below it is my code.
import UIKit
class DetailViewController: UIViewController {
@IBOutlet weak var itemTextView: UITextView!
var txtString: String?
var txtTitleBar:String?
override func viewDidLoad() {
super.viewDidLoad()
//navigationController?.navigationItem.title = "Love"
self.title = txtTitleBar
//self.tabBarController?.navigationItem.title = "My Title"
itemTextView.text = txtString
itemTextView.font = UIFont(name: "Arial-Regular", size:20)
itemTextView.font = .systemFont(ofSize: 25)
(itemTextView.font?.lineHeight)! * 5
}
}
推荐答案
您需要使用属性字符串并分配段落样式.例如:
You need to use an attributed string and assign a paragraph style. For example:
let style = NSMutableParagraphStyle()
style.lineSpacing = 20
let attributes = [NSParagraphStyleAttributeName : style]
textView.attributedText = NSAttributedString(string: txtString, attributes: attributes)
有关此属性字符串用法的更多详细信息,请参见此SO答案:如何使用Swift创建属性字符串?
See this SO answer for more details on attributed string usage: How do I make an attributed string using Swift?
这篇关于无法在UITextView中应用行距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文