9

How would I set the Line Height or Line Spacing in an NSTextView (i.e. how tall each line is, or how much space is between each line)?

Shekhar Gupta
  • 6,206
  • 3
  • 30
  • 50
Joshua
  • 15,200
  • 21
  • 100
  • 172

2 Answers2

21

leave the answer in case someone need:

NSMutableParagraphStyle * myStyle = [[NSMutableParagraphStyle alloc] init];
[myStyle setLineSpacing:10.0];
[myTextView setDefaultParagraphStyle:myStyle];
Jiulong Zhao
  • 1,313
  • 1
  • 15
  • 25
  • 1
    +1 from me also. If Apple's documentation was genuinely helpful, Stackoverflow's Xcode developer community would be much smaller! – Custom Bonbons Nov 17 '13 at 17:03
14

Use the - (void)setDefaultParagraphStyle:(NSParagraphStyle *)paragraphStyle method in your NSTextView.

Documentation on NSParagraphStyle

Documentation on NSMutableParagraphStyle

There is a setLineSpacing: method in NSMutableParagraphStyle. There are also methods relating to line height, the methods under "Setting Other Style Information" in the NSMutableParagraphStyle documentation should prove useful.

I think that's what you're looking for.

aleclarson
  • 18,087
  • 14
  • 64
  • 91
Michael
  • 1,477
  • 4
  • 18
  • 27
  • How do I change the NSParagraphStyle to NSMutableParagraphStyle so the setLineSpacing: method will work as this is what I have now (in a NSTextView subclass) http://grab.by/1ppb. And I get that warning for that problem. – Joshua Dec 27 '09 at 18:40
  • Change the (NSParagraphStyle *) to (NSMutableParagraphStyle *) – Michael Dec 27 '09 at 20:13
  • Thanks, I've just down that but it doesn't actually change the line spacing, any idea why? – Joshua Dec 28 '09 at 11:42
  • These links are now dead. –  Dec 10 '16 at 16:00