Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When should you use lineHeightMultiple vs. lineSpacing?

Tags:

ios

uikit

There seem to be two different ways to explicitly set the line height of an attributed string in iOS. Which is the preferred method and why?

https://developer.apple.com/documentation/uikit/nsmutableparagraphstyle/1524596-lineheightmultiple

https://developer.apple.com/documentation/uikit/nsmutableparagraphstyle/1524596-lineheightmultiple

like image 330
garrettmaring Avatar asked Feb 14 '18 17:02

garrettmaring


2 Answers

Note that there are subtle differences to using these parameters, even if you are effectively setting the same distances.

enter image description here

The above shows lineSpacing applied. When selecting text, the spacing is visible below the lines of text. The last spacing is truncated.

enter image description here

The above shows lineHeightMultiple applied. The selection shows the spacing is above the lines of text. The top spacing is NOT truncated.

like image 113
Giles Avatar answered Sep 21 '22 09:09

Giles


Line Spacing is the distance in CGFloat between two lines.

Line Height Multiple the space between each line equal to the value multiply with the line height. Imagine Line Height Multiple = number of new lines for each line.

ie: lineHeightMultiple = 2 will insert 2 "\n" and lineHeightMultiple = 3 will insert "\n".

like image 33
blyscuit Avatar answered Sep 22 '22 09:09

blyscuit