在iOS 8中,我有一个vanilla UITextView,当lineHeightMultiple应用于它的NSMutableParagraphStyle时,它会剪切第一行的顶部,见下图:
看起来,除了后续行之外,lineHeightMultiple还会影响第1行文本.
在UITextView上设置clipsToBounds = false至少会使剪裁的部分显示出来,但是你可以从下图中看到,现在文本的顶部显然位于它的框架上方:
我可以通过在有问题的UITextView上设置顶部约束来补偿clipsToBounds = false来解决这个问题,但这对我来说就像是一个黑客攻击.
我也尝试使用WKWebView来处理有问题的文本,只是设置了css line-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.
我也尝试过设置UITextView的contentInset以及使用系统字体,两者都没有影响.
我的示例代码如下:
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
有没有人遇到过这个并且克服或者是最重要的约束黑客唯一的出路?