On Jun 21, 2009, at 10:44 AM, Ken Tozier wrote:

Hi

I'm working with an NSText view and want to display tab delimited strings in a table format. I don't need a full NSTable, just the ability to break up the text into columns using tab stops. Is there any built-in way to do this? Something like setTabStops?

I looked in NSTextView, NSText, NSTextContainer and NSAttributedString but didn't see anything.

You need to create an NSMutableParagraphStyle, set you tab stops on it with setTabStops: and then add it as an attribute to your attributed string in your text view.

Code written in Mail, YMMV:

NSArray *tabStops = /* your array */

NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[style setTabStops:tabStops];

[[textView textStorage] addAttribute:NSParagraphStyleAttributeName value:style range: /* effective range */ ];

/* if you're doing this in response to a user action you should also update the typing attributes */ NSMutableDictionary *typingAttributes = [[textView typingAttributes] mutableCopy];
[typingAttributes setObject:style forKey:NSParagraphStyleAttributeName];
[textView setTypingAttributes:typingAttributes];

[typingAttributes release];
[style release];



Ashley
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to