• 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
Trouble Subclassing NSButtonCell for Buttons in a nib
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trouble Subclassing NSButtonCell for Buttons in a nib


  • Subject: Trouble Subclassing NSButtonCell for Buttons in a nib
  • From: Arshad Tayyeb <email@hidden>
  • Date: Mon, 23 May 2005 01:04:40 -0700

I'm trying to subclass an NSButton/NSButtonCell so I can get some custom drawing.  Really, the only thing I want to do is make the text a different color (say, red).

My buttons are all now "ColoredButton"s, and I've created an NSButtonCell class.

I've tried two approaches to setting the cell class for my ColoredButtons - and both of them have problems.
1) in the +initialize method, I've added:

       [self setCellClass:[ColoredButtonCell class]];
Also, I added:
+ (Class) cellClass
{
    return [ColoredButtonCell class];
}

Now, this approach seems to do nothing for cells I create in IB.  It seems that other people on this list have seen the same behavior.   OK, I guess that's the way it is.

So, I tried 

2) in ColoredButton's awakeFromNib:
- (void) awakeFromNib
{
    [[self class] setCellClass:[ColoredButtonCell class]];
    ColoredButtonCell *cell = [[ColoredButtonCell alloc] init];
    [self setCell:cell];       
}

 This sort of works, but has some nasty side effects.  Namely, everything I've set up in IB for the NSButton seems to get lost.  This includes the button type, the title (the title becomes "Button" for all of them!), and even the keyequivalents.  So I end up with the red text buttons I want, but they all just say "button", and nothing works.

What fixes this?  Or, is there an easier way to change the text color for an NSButton?  (I also kind of want to override the cell color when the button is clicked).

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Trouble Subclassing NSButtonCell for Buttons in a nib
      • From: j o a r <email@hidden>
  • Prev by Date: Re: How to get NSPersistentDocument to use a subclassed NSManagedContext?
  • Next by Date: Re: Trouble Subclassing NSButtonCell for Buttons in a nib
  • Previous by thread: Using AdressBook's AS plugins in my app
  • Next by thread: Re: Trouble Subclassing NSButtonCell for Buttons in a nib
  • Index(es):
    • Date
    • Thread