Michael,

By implementing -drawRect: in your view class, you become responsible for all drawing in that view. The code below doesn't attempt to draw the text, it only sets a value.

To draw text in the current drawing context, see the - drawAtPoint:withAttributes: method of NSString for one way to to do so.

I won't go into the intricacies of NSControl and NSCell just yet.

-jcr


On Jun 21, 2008, at 12:44 AM, Michael A. Crawford wrote:

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 (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/jcr%40mac.com

This email sent to [EMAIL PROTECTED]

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to