简体   繁体   English

UITextView中的默认行距是多少

[英]What is the default line spacing in UITextView

I want to increase the default line spacing in UITextView by 10 units. 我想将UITextView的默认行距增加10个单位。

Here's how I am doing: 这是我的做法:

NSDictionary *attributesDictionary;
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 30;

attributesDictionary = @{NSParagraphStyleAttributeName : paragraphStyle , NSFontAttributeName: cellFont};

[str addAttributes:attributesDictionary range:NSMakeRange(0, str.length)];
bodyTextView.attributedText = str;

So what is the default value that I should add 10 with and set it the linespacing? 那么我应该加上10并将其设置为行距的默认值是多少?

The default value is 0. 默认值为0。

This can be shown by creating a UITextView with some text and set its font to Helvetica size 12 (which is the default of an NSAttributedString ). 这可以通过创建带有一些文本的UITextView并将其字体设置为Helvetica大小12(这是NSAttributedString的默认值)来显示。 If you then use your code above but set paragraphStyle.lineSpacing = 0 and remove whatever font you're setting in your attributesDictionary you can see that the spacing in your bodyTextView will be identical to the spacing in the non-attributed version. 如果然后使用上面的代码,但将paragraphStyle.lineSpacing = 0 bodyTextView paragraphStyle.lineSpacing = 0设置paragraphStyle.lineSpacing = 0然后删除您在attributesDictionary设置的任何字体,则可以看到bodyTextView中的间距与非归因版本中的间距相同。 I am assuming that this holds true with other fonts (such as whatever you're using in cellFont ) 我假设这对于其他字体也适用(例如您在cellFont使用的cellFont

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM