Re: Setting text color in a NSFormCell
Re: Setting text color in a NSFormCell
- Subject: Re: Setting text color in a NSFormCell
- From: Michael Babin <email@hidden>
- Date: Tue, 23 Oct 2007 08:09:08 -0500
On Oct 22, 2007, at 6:35 PM, R.L. Grigg wrote:
Hi Nick,
I was able to get setAttributedStringValue working, using an
attributes dictionary. But I'm having difficulty getting the string
centered in the cell:
NSDictionary *textDict=[NSDictionary dictionaryWithObjectsAndKeys:
[NSFont boldSystemFontOfSize:
10],NSFontAttributeName,
[NSColor
redColor],NSForegroundColorAttributeName,nil];
NSAttributedString *attrStr=[[[NSAttributedString alloc]
initWithString:descrip
attributes:textDict]
autorelease];
[fcell setAlignment:NSCenterTextAlignment];
[fcell setAttributedStringValue:attrStr];
This displays the text (from NSString var 'descrip') in bold red,
but its left justified. Maybe I need to set NSCenterTextAlignment
somehow in textDict also, but I don't see how to do that...?
Try using a paragraph style, as in:
NSMutableParagraphStyle *paragraphStyle =
[[[NSMutableParagraphStyle alloc] init] autorelease];
[paragraphStyle setAlignment: NSCenterTextAlignment];
NSDictionary *textDict=[NSDictionary dictionaryWithObjectsAndKeys:
[NSFont boldSystemFontOfSize:
10],NSFontAttributeName,
[NSColor
redColor],NSForegroundColorAttributeName,
paragraphStyle,
NSParagraphStyleAttributeName,
nil];
NSAttributedString *attrStr=[[[NSAttributedString alloc]
initWithString:descrip
attributes:textDict]
autorelease];
[fcell setAttributedStringValue:attrStr];
- Mike
_______________________________________________
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