【发布时间】:2017-03-31 12:05:17
【问题描述】:
当我粘贴文本时,我得到了错误的文本高度。这不算。我只能得到第一行的高度。但是,如果我单击返回键,每一行文本都像“Software\nis\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 是什么意思..?我把代码放在下面
标签: ios swift xcode string text