Re: NSBox Colored Background
Re: NSBox Colored Background
- Subject: Re: NSBox Colored Background
- From: August Trometer <email@hidden>
- Date: Tue, 26 Oct 2004 12:49:41 -0500
The controls are subviews -- I even rebuilt that section in Interface
Builder to see if that fixed the problem. And I tried Graham's
suggestion. You can't set isOpaque directly (as far as I can tell), but
I did try displayIfNeededIgnoringOpacity: and various other redraw
method with no luck.
Here's my drawRect code. I've tried the [super drawRect:aRect] both
before and after the path creation, with no difference either way.
- (void) drawRect: (NSRect) aRect
{
NSRect newRect;
// change dimensions for fill
newRect.origin.x = aRect.origin.x + 1;
newRect.origin.y = aRect.origin.y + 4;
newRect.size.height = aRect.size.height - 5;
newRect.size.width = aRect.size.width - 1;
// draw the filled rounded rectangle
NSBezierPath* path = [NSBezierPath bezierPath];
float radius = MIN(6, 0.5f * MIN(NSWidth(newRect), NSHeight(newRect)));
NSRect rect = NSInsetRect(newRect, radius, radius);
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect),
NSMinY(rect)) radius:radius startAngle:180.0 endAngle:270.0];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect),
NSMinY(rect)) radius:radius startAngle:270.0 endAngle:360.0];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMaxX(rect),
NSMaxY(rect)) radius:radius startAngle: 0.0 endAngle: 90.0];
[path appendBezierPathWithArcWithCenter:NSMakePoint(NSMinX(rect),
NSMaxY(rect)) radius:radius startAngle: 90.0 endAngle:180.0];
[path closePath];
// set grey color
[[NSColor colorWithCalibratedHue:0 saturation:0 brightness:.8
alpha:1.0] set];
[path fill];
// draw normal rect with clear color
[[NSColor clearColor] set];
[super drawRect:aRect];
}
Thanks!
August
On Oct 26, 2004, at 12:17 PM, Michael Becker wrote:
Am 26.10.2004 um 00:22 schrieb August Trometer:
I'm trying to get an NSBox much like Apple has in iPhoto -- rounded,
inset rectangle with a colored, non-metal background.
I've written a subclass which uses drawRect method to create a
NSBezierPath inside the box. I can get the color just fine, and I can
get the inset just fine. However, all the controls inside (such as an
NSPopUpButton) still show metal as the background. Strangely, when I
resize the window, the metal goes away, but as soon as the control is
used, it appears again. And apparently you can't change the
background of a Button. Finally, I've tried redrawing the controls in
awakeFromNib with no luck.
I have done the same thing, which works just fine. Maybe you can
provide the code of your drawRect: method in the NSBox subclass. Also
it might be important that the controls are really subviews of your
box.
Regards,
Michael
_______________________________________________
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