How do I draw text on a custom button?
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