为什么单行文本有新行?
Why does single line text have new line?
我一直在为 UITableViewCell
的 UILabel
使用属性文本。
有时,即使文本是单行的,文本也会换行。
我的代码在这里
if notnullCheck(catchcopy){
//行間
let attributedText = NSMutableAttributedString(string: catchcopy!)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 5
attributedText.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, attributedText.length))
self.catchcopyLabel.attributedText = attributedText
}
self.catchcopyLabel.sizeToFit()
多行文字时,文字高度为33。
单行文字时文字高度为14。
但有时,当单行文本为 19 时,文本高度为 19。
行高为19时,文本换行
这是什么问题?
以下文字为调试日志。
(98.0, 14.0)
勤務地表記確認
(230.0, 19.0)
ケイサイカキンなしんこうぃあ 02
两个文本也是单一的line.But高度不一样。
假设您使用 'HiraKakuProN-W6' 字体并且其大小为 14。
不是换行的问题,而是日文space字符(全角スペース)的问题。
如果删除日文 space 个字符,您将获得 14 的高度。
这种怪事很多年前就遇到过,
所以我认为这是HiraXXXXX-XX字体的BUG。
我一直在为 UITableViewCell
的 UILabel
使用属性文本。
有时,即使文本是单行的,文本也会换行。
我的代码在这里
if notnullCheck(catchcopy){
//行間
let attributedText = NSMutableAttributedString(string: catchcopy!)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 5
attributedText.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, attributedText.length))
self.catchcopyLabel.attributedText = attributedText
}
self.catchcopyLabel.sizeToFit()
多行文字时,文字高度为33。 单行文字时文字高度为14。 但有时,当单行文本为 19 时,文本高度为 19。 行高为19时,文本换行
这是什么问题?
以下文字为调试日志。
(98.0, 14.0)
勤務地表記確認
(230.0, 19.0)
ケイサイカキンなしんこうぃあ 02
两个文本也是单一的line.But高度不一样。
假设您使用 'HiraKakuProN-W6' 字体并且其大小为 14。
不是换行的问题,而是日文space字符(全角スペース)的问题。
如果删除日文 space 个字符,您将获得 14 的高度。
这种怪事很多年前就遇到过,
所以我认为这是HiraXXXXX-XX字体的BUG。