• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problems with NSTextField and attributed strings
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with NSTextField and attributed strings


  • Subject: Re: Problems with NSTextField and attributed strings
  • From: Tim Cartwright <email@hidden>
  • Date: Wed, 21 Jul 2004 15:52:43 -0500

Other attributes embedded in the text field value are displaying, but no matter what I set for the paragraph spacing before, I don't see a change in line spacing. Does "\n" not separate paragraphs? What am I doing wrong?

Not sure on this, but I believe that "space before" isn't used for the for the first paragraph (since it's at the "top", just like "space after" on the last paragraph is ignored because there's nothing after it).

I agree with Glenn's interpretation of paragraph spacing. So, it's worth re-iterating that I'm dealing with multiple lines. For example:

Line 1 (normal)
Line 2 (paragraph space before = 20.0)
Line 3 (paragraph space before = 20.0)

I would expect to see an extra 20 point vertical space between Line 1 and Line 2, and between Line 2 and Line 3.

If you just want an extra 20 points between the paragraphs, try "setParagraphSpacing:" (since that works all the way back to 10.0, while setParagraphSpacingBefore: requires 10.3)

Sorry, I should have mentioned that I tried "setParagraphSpacing:" as well. That's actually how the code reads right now, and I'm not seeing ANY paragraph spacing.

Is it potentially a problem with applying the paragraph style to one attributed string, which is in turn appended to another attributed string that does not carry the same paragraph style? Here's code to build my three-line example:

// Prepare paragraph style
NSMutableParagraphStyle * style = [[NSMutableParagraphStyle alloc] init];
[style setParagraphSpacing: 18.0]; // 1/4-inch -- should be visible

// Compose a three-line field
NSMutableAttributedString * fieldValue = [[NSMutableAttributedString alloc] initWithString: @"Line 1\n"];
NSMutableAttributedString * line2 = [[NSMutableAttributedString alloc] initWithString: @"Line 2\n"];
NSMutableAttributedString * line3 = [[NSMutableAttributedString alloc] initWithString: @"Line 3"];
[line2 addAttribute: NSParagraphStyleAttributeName value: style range: NSMakeRange(0, [line2 length])];
[fieldValue appendAttributedString: line2];
[fieldValue appendAttributedString: line3];
[myTextField setAttributedStringValue: fieldValue];

My understanding is that this code should put 18.0 points of paragraph space between Line 2 and Line 3.

To be extra sure, I copied the above code into my application, and the spacing between lines is the same -- no extra space.

Also, I've tried adding a "beginEditing" / "endEditing" pair around the modifications to "fieldValue". I didn't think it would have any effect, and indeed it did not.

-- Tim
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.


References: 
 >Problems with NSTextField and attributed strings (From: Tim Cartwright <email@hidden>)
 >Re: Problems with NSTextField and attributed strings (From: Glenn Andreas <email@hidden>)
 >Re: Problems with NSTextField and attributed strings (From: Tim Cartwright <email@hidden>)
 >Re: Problems with NSTextField and attributed strings (From: Glenn Andreas <email@hidden>)

  • Prev by Date: Re: Can't divide integers ?
  • Next by Date: OT: what is core data
  • Previous by thread: Re: Problems with NSTextField and attributed strings
  • Next by thread: Re: Problems with NSTextField and attributed strings
  • Index(es):
    • Date
    • Thread