Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Setting text color in a NSFormCell



On Oct 22, 2007, at 3:37 PM, Nick Zitzmann wrote:

On Oct 23, 2007, at 11:03 AM, R.L. Grigg wrote:

Newb question: Is there a way to set/change the color of the text displayed in a NSFormCell?

Yes.

NSFormCell does'nt seem to have methods like setTextColor or setBackgroundColor etc. so I'm not sure how to approach this. At times I need to display red text in certain cells when data from a array of sensors goes out of range and set it back to black when those elements indicate normal conditions.

NSFormCell does have a -setAttributedStringValue: method. You may, however, be able to automate what you're trying to do by using NSNumberFormatter.

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...?
Thanks,
Russ


_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >Setting text color in a NSFormCell (From: "R.L. Grigg" <email@hidden>)
 >Re: Setting text color in a NSFormCell (From: Nick Zitzmann <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.