在 iOS 8 中,我有一个普通版本UITextView
当 a 时,会剪辑第一行的顶部lineHeightMultiple
被应用到它的NSMutableParagraphStyle
,见下图:
看起来好像lineHeightMultiple
除了后续行之外,还会影响文本的第一行。
Setting clipsToBounds = false
on the UITextView
至少会显示剪切的部分,但您可以从下图中看到,现在文本的顶部显然位于其框架上方:
我可以通过仅对违规者设置最高约束来解决此问题UITextView
来补偿clipsToBounds = false
但这对我来说就像是一种黑客攻击。
我也尝试过使用WKWebView
对于有问题的文本,只需设置 cssline-height
财产,而且效果很好。不过,当涉及到 UITextView 时,我一定缺少一些东西。
另外,设置lineSpacing
根据文档,段落样式小于 0 没有影响:
The distance in points between the bottom of one line fragment
and the top of the next.
**This value is always nonnegative.**
This value is included in the line fragment heights in the
layout manager.
我也尝试过设置contentInset
of the UITextView
以及使用系统字体,两者都没有影响。
我的此设置的示例代码如下:
let text = "THIS IS A MULTILINE RUN OF TEXT"
let font = UIFont(name: "MyFontName", size: 31.0)!
// let font = UIFont.systemFontOfSize(31.0)
let paragraph = NSMutableParagraphStyle()
paragraph.lineHeightMultiple = 0.75
paragraph.alignment = NSTextAlignment.Center
let attributes = [
NSParagraphStyleAttributeName: paragraph,
NSFontAttributeName: font
]
titleView.attributedText = NSAttributedString(string: text, attributes: attributes)
// titleView.contentInset = UIEdgeInsets(top: 50.0, left: 0.0, bottom: 0.0, right: 0.0)
titleView.clipsToBounds = false
有没有人遇到过这个问题并克服了,或者顶级约束黑客是唯一的出路?