I want to increase the default line spacing in UITextView
by 10 units.
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?
lineSpacinghas the following declaration: The distance in points between the bottom of one line fragment and the top of the next. var lineSpacing: CGFloat { get set } The following code shows how to implement lineSpacingin order to have a specific line spacing for some attributed text in your UItextView.
The importance of line spacing for UX design comes from the power it has to render a block of text more or less readable. Line spacing is commonly measured as a percentage of font size. Conventional wisdom is that line spacing of 130%-150% is ideal for readability.
Word's default spacing is 1.08 lines, which is somewhat more than single-spaced. You can change this by using the Format menu and selecting Line Spacing. What is the spacing in Microsoft Word? You may change the line spacing in Microsoft Word to be single spaced (one line high), double spaced (two lines high), or any other quantity you wish.
Line spacing is commonly measured as a percentage of font size. Conventional wisdom is that line spacing of 130%-150% is ideal for readability. In fact, anything from about 120% up to 200% is acceptable, but 140% tends to be the most quoted sweet spot.
The default value is 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
). 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. I am assuming that this holds true with other fonts (such as whatever you're using in cellFont
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With