当我粘贴文本,我得到错误的文字高度。它不算数。我只能得到第一线的高度。但是,如果我点击返回键,每行文本都像“Software \ n \ n \ nawesome”,它运行良好。这里是代码:当我粘贴文本,它不能得到文本的高度
let font = UIFont(name: "HelveticaNeue", size: 18)!
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .center
paragraphStyle.lineSpacing = 8
let textFontAttributes = [
NSFontAttributeName: font,
NSForegroundColorAttributeName: UIColor(red: 0.149, green: 0.149, blue: 0.145, alpha: 1.00),
NSParagraphStyleAttributeName: paragraphStyle
] as [String : Any]
let string:NSString = NSString(string: self.txtView.text)
let size:CGSize = string.size(attributes: textFontAttributes)
print("size.height")
但是,当我输入一些文本,我可以得到正确的文本高度。
如何获得正确的文本高度?
@returntrue是什么意思..?我把下面的代码放在 –