Re: Setting vertical alignment for a NSTextFieldCell ?
Re: Setting vertical alignment for a NSTextFieldCell ?
- Subject: Re: Setting vertical alignment for a NSTextFieldCell ?
- From: Ryan Stevens <email@hidden>
- Date: Wed, 27 Jul 2005 11:44:43 -0700
With attributed strings you've got way more control...
Alignments, fonts, truncation, head/tail indent, baseline...tons of
customization options. These are also fairly easy to expose to your
users should you want to.
Using a subclass is easier but I've done it both ways and attributed
strings are neater.
On Jul 27, 2005, at 11:05 AM, Ryan Britton wrote:
NSCells have a two-stage drawing. They might have separate methods
they call internally, but the two main ones are
drawWithFrame:inView: and drawInteriorWithFrame:inView:. The first
one is for drawing the "decoration" of the cell. In the case of
NSTextFieldCell, this is the background and bezel style for the
cell. The second is for drawing the actual contents of the cell,
which for NSTextFieldCell, is the text.
So, to offset the text, you might do something like this in your
subclass:
- (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView *)
controlView
{
frame.origin.y += 4.0;
frame.size.height -= 4.0;
[super drawInteriorWithFrame:frame inView:controlView];
}
That offsets the text by 4 pixels upwards assuming it's a lower-
left origin coordinate system. If you want your text centered,
then you're going to have to do something to calculate the size of
the text and use those values to calculate the right offset instead
of hard values.
On Jul 27, 2005, at 9:00 AM, Adam Holt wrote:
Thanks Ryan for the pointers.
I had this nervous feeling that the answer might come back as
"subclass and
override", always a terrifying notion for a learner cocoahead /
obj-cite.
Presumably I need to understand in more detail how this
drawInteriorWithFrame:inView: method works in order to be able to
override
it. Any tips on where to start with this would be very welcome!
Thanks,
Adam.
On 26/7/05 11:25 pm, "Ryan Britton" <email@hidden> wrote:
There is no way to adjust the vertical alignment without subclassing
something or getting into the ATSUI stuff. Subclassing
NSTextFieldCell and overriding drawInteriorWithFrame:inView: to use
an adjusted frame would be the easiest I think. The ATSUI stuff
will
give you far more control, but it gets to be very complex to
implement anything even resembling the existing text field classes.
On Jul 26, 2005, at 2:59 PM, Adam Holt wrote:
I have an NSTableView that for one of its NSTableColumn's I have
created a
new NSTextFieldCell for and assigned it with setDataCell. The
purpose is to
be able to change the font size just for that column of the table.
Here's my code:
- (void)awakeFromNib
{
NSTextFieldCell *cell;
cell = [[NSTextFieldCell alloc] init];
[cell setAlignment:NSCenterTextAlignment];
[cell setFont:[NSFont fontWithName:@"Lucida Grande" size:
20.0]];
NSTableColumn *desiredColumn = [myTableView
tableColumnWithIdentifier:@"3"];
[desiredColumn setDataCell:cell];
[cell release];
}
This works as I would expect... to a point. The problem I have is
that as I
use a larger font size, the text drops vertically in the cell so
that it
clips at the bottom whilst there is still plenty of space between
the top of
the text and the ceiling of the cell.
Is there any way I can vertically align my text?
Cheers...
Adam.
_______________________________________________
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