• 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
RE: how to change NSButton color
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: how to change NSButton color


  • Subject: RE: how to change NSButton color
  • From: Shawn Bakhtiar <email@hidden>
  • Date: Mon, 24 Jan 2011 12:37:48 -0500
  • Importance: Normal

Deriving a class from NSButton is not a daunting task by any imagination, you only need understand that NSButton is nothing more than a wrapper class for NSButtonCell.

As for the HIG.... it is a recommendation, and it indeed serves a purpose (IE for programmers who thing all their users are programmers. However, you can not design and effective POS (Point of Sale/Service) system using only what the toolkit provides.

The reason you can not change the color, is because most of these are custom drawn (perhaps even NSImages), just like you would when you override the ButtonCell with your own implementation of it. Apple has simply provided a base set which are very nice and clean, and should be used as examples for future work. This is MUCH cleaner than trying to expose every possible option for changing the look of a control. Why? When you can simply expose the draw function, which apple has done; which it would not have, if it did not intend for users to to user :)

The fact of the mater is I too need buttons that are much larger


//

//  CustomButtonCell.h

//

//

#import <Cocoa/Cocoa.h>
@interface POSButtonCell : NSButtonCell <NSCopying> {}
- (id)copyWithZone:(NSZone *)zone;
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView;
@end

//
//  CustomButtonCell.m
//
#import "POSButtonCell.h"

@implementation POSButtonCell
- (id) init {

    self = [super init];

    if (self) {    /* PUT YOUR INIT CODE HERE  */  }

    return self;
}

// So you can use with NSMatrix
- (id)copyWithZone:(NSZone *)zone{ return [[POSButtonCell alloc] init]; }


- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
{
    switch ([self state]) {
        case NSOnState :
                 // Draw on state
           break;
        case NSMixedState :
                // Draw mixed state
            break;
        default:
        case NSOffState :
...
            break;
    }


}


@end



> From: email@hidden
> Date: Sun, 23 Jan 2011 09:43:07 -0600
> To: email@hidden
> CC: email@hidden
> Subject: Re: how to change NSButton color
>
>
> On Jan 23, 2011, at 8:14 AM, Dianne wrote:
>
> > I want to change the buttons color from the normal gray to dark gray to indicate
> > whether the button is assigned to other values other than its default value.
> >
> > Is there any other or best way to do this? what you can suggest?
> > Thanks,
> > Yani
> >
> >
> >
> Normally, if a button changes its functionality, you should at least change the label or icon inside the button.
> Effectively, you are changing the button to perform a different action.
> You might actually want to consider what the button needs to do in your application and revisit the types of controls already available in Cocoa and described in the Human Interface Guidelines. There might be a better control for the purpose of this button._______________________________________________
>
> 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
 		 	   		  _______________________________________________

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

  • Follow-Ups:
    • Weather API for commercial use in iOS app
      • From: Roger Dalal <email@hidden>
References: 
 >how to change NSButton color (From: Dianne <email@hidden>)
 >Re: how to change NSButton color (From: Kyle Sluder <email@hidden>)
 >Re: how to change NSButton color (From: Dianne <email@hidden>)
 >Re: how to change NSButton color (From: John Joyce <email@hidden>)

  • Prev by Date: MemoryWarning and loadView
  • Next by Date: NSOutlineView syncing demo project
  • Previous by thread: Re: how to change NSButton color
  • Next by thread: Weather API for commercial use in iOS app
  • Index(es):
    • Date
    • Thread