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: Ken Tozier <email@hidden>
- Date: Sun, 21 Jun 2009 18:44:38 -0400
Thanks Ashley
I tried your snippet, but am getting the following error:
2009-06-21 18:32:34.912 QuarkXPress[4956:10b] *** -[NSCFNumber
location]: unrecognized selector sent to instance 0x300bc300
2009-06-21 18:32:34.914 QuarkXPress[4956:10b] <NSATSTypesetter:
0x23c60e70>: Exception *** -[NSCFNumber location]: unrecognized
selector sent to instance 0x300bc300 raised during typesetting layout
manager <NSLayoutManager: 0x300ca260>
1 containers, text backing has 3006 characters
selected character range {3006, 0} affinity: downstream
granularity: character
marked character range {3006, 0}
Currently holding 3006 glyphs.
Glyph tree contents: 3006 characters, 3006 glyphs, 1 nodes, 32
node bytes, 4096 storage bytes, 4128 total bytes, 1.37 bytes per
character, 1.37 bytes per glyph
Layout tree contents: 3006 characters, 3006 glyphs, 0 laid
glyphs, 0 laid line fragments, 1 nodes, 32 node bytes, 0 storage
bytes, 32 total bytes, 0.01 bytes per character, 0.01 bytes per glyph,
0.00 laid glyphs per laid line fragment, 0.00 bytes per laid line
fragment
, glyph range {0 25}. Ignoring...
Here's how I interpreted your code
NSArray *tabStops = [[[NSArray alloc] initWithObjects:
[NSNumber numberWithInt: 70],
[NSNumber numberWithInt: 400],
[NSNumber numberWithInt: 460],
nil]
autorelease];
style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
[style setTabStops: tabStops];
NSMutableAttributedString *missingAds = [[[NSMutableAttributedString
alloc] init] autorelease];
/* add some text to missingAds here */
[missingAds addAttribute: NSParagraphStyleAttributeName
value: style
range: NSMakeRange(0, [missingAds length])];
[[resultsView textStorage] setAttributedString: missingAds];
If i comment out the "addAttribute" line, I don't get the error, Can't
seem to get this to work. Where am I messing up?
Thanks again.
On Jun 21, 2009, at 12:53 PM, Ashley Clark wrote:
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