0

I am trying to make the line space a little less than the default for a small window.

I have code similar to this question: How to Increase Line spacing in UILabel in Swift

let title = "This is text that will be long enough to form two lines"
let styles = NSMutableParagraphStyle()
styles.lineSpacing = 0.1
let attribs = [
    NSAttributedString.Key.paragraphStyle:styles
]
let attrString:NSAttributedString = NSAttributedString.init(string: title, attributes: attribs)
introText.attributedStringValue = attrString

While changing lineSpacing to 10 makes a noticeable difference, I can't see a difference if I make it less than 1.

Here is what 0.1 looks like:

enter image description here

Dave Stein
  • 8,653
  • 13
  • 56
  • 104

2 Answers2

1

Line spacing is measured in points, not lines. There's basically no such thing as a fraction of a point (for drawing purposes; I am simplifying, since retina screens do exist). Zero is the minimum, and when you say 0.1, you are there; you can't reduce the leading any further.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I see. So if zero is the lowest, it seems that 0 is safeguarded so you can't squish words on top of each other. I was hoping to make things a smidge closer (in above screenshot I just added), but I guess I can't – Dave Stein Apr 25 '19 at 19:06
  • Okay so it looks like the problem is merely that you asked the wrong question? Your code assumes that we want to change the `minimumLineHeight` but it's the `maximumLineHeight` you want to play with. See https://stackoverflow.com/questions/19554855/really-close-lines-with-nsattributedstring – matt Apr 25 '19 at 21:09
0

Keep in mind the relationship of points to pixels. For most recent devices, a point represents two or three pixels. I have set a UIView with a height of 0.5, used as a divider, which is about 1 pixel on many devices, and been able to see the difference. A height of 0.1 is probably rounded off to nothing, though.

GntlmnBndt
  • 249
  • 2
  • 6