Re: Possible to set tab stops in an NSTextView?
Re: Possible to set tab stops in an NSTextView?
- Subject: Re: Possible to set tab stops in an NSTextView?
- From: Ashley Clark <email@hidden>
- Date: Sun, 21 Jun 2009 11:53:50 -0500
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 (email@hidden)
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:
This email sent to email@hidden