• 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 do I draw text on a custom button?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How do I draw text on a custom button?


  • Subject: How do I draw text on a custom button?
  • From: "Michael A. Crawford" <email@hidden>
  • Date: Sat, 21 Jun 2008 00:44:07 -0700

I'm using a CustomView that inherits from NSButton. I have no problem drawing the graphical representation of the button in the view but it is not immediately obvious to me how to draw text. setTitle does not work with my custom button. Can you point me to some examples? Here is the code:

#import <Cocoa/Cocoa.h>

@interface TwoStateButton : NSButton
{}

@end

- (void)drawRect:(NSRect)rect
{
	// draw initial black button
	NSRect bounds = [self bounds];
	[[NSColor blackColor] set];
	[NSBezierPath fillRect:bounds];

	// draw green LED inset in button (grey if not on)
	bounds.origin.x += (bounds.size.width * 0.25) / 2;
	bounds.origin.y += bounds.size.height * 0.25;
	bounds.size.width *= 0.75;
	bounds.size.height *=  0.25;

	if ( NSOnState == [self state] )
	{
		[[NSColor greenColor] set];
	}
	else
	{
		[[NSColor lightGrayColor] set];
	}

	[NSBezierPath fillRect:bounds];
	[self setTitle:@"NDB"];
}

_______________________________________________

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:
    • Re: How do I draw text on a custom button?
      • From: "John C. Randolph" <email@hidden>
  • Prev by Date: Re: Race in Apple's NSTreeContoller/NSOutlineView
  • Next by Date: Re: Fundamental mistake in my understanding of use of classes/instances/encapsulation/messaging
  • Previous by thread: Re: Bindings Concept Question
  • Next by thread: Re: How do I draw text on a custom button?
  • Index(es):
    • Date
    • Thread