RE: NSPopUpButton - aligning to top vertically (SOLVED)
RE: NSPopUpButton - aligning to top vertically (SOLVED)
- Subject: RE: NSPopUpButton - aligning to top vertically (SOLVED)
- From: Keith Blount <email@hidden>
- Date: Wed, 1 Mar 2006 07:37:16 -0800 (PST)
Okay, I worked this one out on my own - it was pretty
simple, I had just overlooked the obvious. I did have
to subclass NSPopUpButtonCell - I just had to trick it
into thinking that the cell was not as tall as it was,
so that the popup only gets drawn at the top. Here's
the code, for anybody searching the archives with the
same problem:
// KBTopAlignedPopUpButtonCell - for use in table or
// outline views that allow variable row heights.
// Just set rowHeight to the default rowHeight of
// the tableView or outlineView in which the cell
// is used.
@interface KBTopAlignedPopUpButtonCell :
NSPopUpButtonCell
{
float rowHeight;
}
- (id)initWithRowHeight:(float)height;
- (void)setRowHeight:(float)height;
- (float)rowHeight;
@end
@implementation KBTopAlignedPopUpButtonCell
- (id)init
{
return [self initWithRowHeight:16.0];
}
- (id)initWithRowHeight:(float)height
{
if (self = [super init])
{
rowHeight = height;
[self setBordered:NO];
}
return self;
}
- (void)setRowHeight:(float)height
{
rowHeight = height;
}
- (float)rowHeight
{
return rowHeight;
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView
*)controlView
{
// Force the cell only to draw within the standard
row height, so
// that it draws at the top in tables or outlines
with variable row heights.
cellFrame.size.height = rowHeight;
[super drawWithFrame:cellFrame inView:controlView];
}
@end
I hope the code is useful to someone else.
All the best,
Keith
--- ORIGINAL MESSAGE ---
Hi,
NSPopUpButton aligns its text and image, by default,
to the centre of its cell. Is there any easy way to
change this so that it is aligned to the text? I have
an outline view in which variable row heights are
allowed (using Tiger's -outlineView:heightOfRowByItem:
delegate method), and it looks very ugly with the
popup buttons aligned to the centre when text is
aligned to the top.
I am guessing that I will need to subclass
NSPopUpButtonCell to achieve this (in particular,
-drawWithFrame:inControlView:), but so far my attempts
have been very limited in their success.
Has anybody do something similar, or know how to do
this?
Many thanks in advance for any suggestions.
All the best,
Keith
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
_______________________________________________
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