Re: NSMutableAttributeString, fonts and alignment
Re: NSMutableAttributeString, fonts and alignment
- Subject: Re: NSMutableAttributeString, fonts and alignment
- From: Vince DeMarco <email@hidden>
- Date: Wed, 19 Dec 2001 09:39:20 -0800
On Tuesday, December 18, 2001, at 08:36 pm, Simson Garfinkel wrote:
What's missing is some way of setting the strings alignment. That appears
to
be set through the setAlignment:range: method.
Unfortunately, there appears to be no way to put an Alignment into a
dictionary. (It's not defined). So I have code that looks like this:
- (void)setColor:(NSColor *)aColor
{
[dict setObject:aColor forKey:NSForegroundColorAttributeName];
[text setAttributes:dict range:NSMakeRange(0,[text length])];
[text setAlignment:NSCenterTextAlignment range:NSMakeRange(0,[text
length])]; // bug in appkit
}
I think that this is pretty ugly. I'm sure that I can hard-code the
correct
key for alignment, but I don't want to do that. I want to know what the
APPKIT_EXTERN is. Anybody know anything I don't?
Try this
{
NSMutableParagraphStyle *modifiedStyle;
NSTextTab *tabStop;
tabStop = [[NSTextTab alloc] initWithType:NSLeftTabStopType
location:100.0];
modifiedStyle = [[NSMutableParagraphStyle alloc] init];
[modifiedStyle setTabStops:[NSArray arrayWithObject:tabStop]];
[[textView textStorage] addAttribute:NSParagraphStyleAttributeName
value:modifiedStyle range:range];
[tabStop release];
[modifiedStyle release];
}
NSParagraphStyle has this method
- (void)setAlignment:(NSTextAlignment)alignment;