Re: Programmatically creating NSButton
Re: Programmatically creating NSButton
- Subject: Re: Programmatically creating NSButton
- From: Greg Hulands <email@hidden>
- Date: Sat, 24 Apr 2004 23:35:18 +1000
What I have now done is created a prototype button in IB and made
connections through to them so I can access the cell and the exact same
thing is happening when using the cell of a "properly created" button.
For instance, the text is not vertically aligned like it should be
(center) and the key equivalent is not shown, in this case the button
should be blue for "\r".
This is really quite puzzling as there seems to be something not
happening when just drawing the cell.
Here is the code that captures the button cell into an image.
- (NSImage *)btnGenerator:(NSButtonCell *)btn
{
NSSize size = [btn cellSize];
size.width += 2 * [padding floatValue];
NSImage *img = [[NSImage alloc] initWithSize:size];
NSRect frame = NSMakeRect(0,0,size.width, size.height);
[img lockFocus];
[[NSColor clearColor] set];
NSRectFill(frame);
[btn drawWithFrame:frame
inView:nil];
[img unlockFocus];
return [img autorelease];
}
The only thing I can think of is that a NSButtonCell requires
information from the NSButton to draw itself correctly, but this
doesn't seem right as it would defeat the purpose of cells.
Baffling, Bloody Baffling I tell you!
Greg
On 24/04/2004, at 10:58 PM, Jeremy Dronfield wrote:
>
On 24 Apr 2004, at 4:43 am, Greg Hulands wrote:
>
>
> Hi,
>
> I am trying to create a rounded aqua button, but the text in the
>
> button
>
> seems to be positioned at the bottom of the button, not in the center.
>
>
>
> [aqua setButtonType:NSMomentaryPushButton];
>
> [aqua setBordered:YES];
>
> [aqua setBezelStyle:NSRoundedBezelStyle];
>
> [aqua setImagePosition:NSNoImage];
>
> [aqua setAlignment:NSCenterTextAlignment];
>
>
>
> What am I doing wrong?
>
>
Nothing obvious. Some suggestions, though. Try sending all these
>
methods (except -setBordered:) to [aqua cell] instead of the button
>
itself. Also, try leaving out -setAlignment: altogether. I've found
>
with programmatically created buttons that they don't always display
>
properly unless these methods are sent to the button cell. (Also, you
>
shouldn't need to -setBordered:YES, since buttons are bordered by
>
default.)
>
>
Hope this helps.
>
>
-Jeremy
>
>
===================================
>
SkoobySoft, home of viJournal
>
email: email@hidden or visit:
>
http://freespace.virgin.net/jeremy.dronfield/skoobysoft.html
>
===================================
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.