• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
How to set the color of a string on a NSButton?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to set the color of a string on a NSButton?


  • Subject: How to set the color of a string on a NSButton?
  • From: David Hinz <email@hidden>
  • Date: Thu, 23 Nov 2006 00:10:07 -0700


What is the easiest way to change the color of the string on a NSButton where string was set through Interface Builder?


In the -(void)awakeFromNib method I tried getting a NSMutableAttributeString from the button then using the setAttributes:range: method. But that doesn't seem to work.

The error I got at run time is:
-[NSCFString setAttributes:range:]: selector not recognized [self = 0x34df00]


This is what I tried:

NSDictionary *textDictionary = [NSDictionary dictionaryWithObject: [NSColor whiteColor]
forKey:NSForegroundColorAttributeName];
[(NSMutableAttributedString *)([[threeButton stringValue] mutableCopy]) setAttributes:textDictionary
range:NSMakeRange(0, [[threeButton stringValue] length])];



There must be an easier way to set the text color on a NSButton. Setting the background color was easy.


	[[threeButton cell] setBackgroundColor:[NSColor brownColor]];


Thanks, David.



_______________________________________________

Cocoa-dev mailing list      (email@hidden)

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


  • Follow-Ups:
    • Re: How to set the color of a string on a NSButton?
      • From: Scott Stevenson <email@hidden>
    • Re: How to set the color of a string on a NSButton?
      • From: "stephen joseph butler" <email@hidden>
    • Re: How to set the color of a string on a NSButton?
      • From: Nick Zitzmann <email@hidden>
  • Prev by Date: Re: NUL characters in NSString cause unexpected results
  • Next by Date: Re: How to set the color of a string on a NSButton?
  • Previous by thread: Re: NUL characters in NSString cause unexpected results
  • Next by thread: Re: How to set the color of a string on a NSButton?
  • Index(es):
    • Date
    • Thread