Re: Set TableView font and rowHeight
Re: Set TableView font and rowHeight
- Subject: Re: Set TableView font and rowHeight
- From: Sherm Pendley <email@hidden>
- Date: Mon, 2 Apr 2007 06:28:09 -0400
On Apr 2, 2007, at 5:21 AM, Ivan C Myrvold wrote:
I am changing the font of an NSTableView with the font panel. In
the NSTableView delegate method
tableView:willDisplayCell:forTableColumn:row: I have:
NSRect brect = [[self newFont] boundingRectForFont];
[aCell setFont: newFont];
[aTableView setRowHeight:brect.size.height];
But for some fonts, the table row height is not correct, e.g.
Lucida Bright font gets the text in the table view clipped at the
bottom.
I suspect I have to do something more to get this right, but I have
run out of ideas.
The bounding rect doesn't take into account the ascent or descent of
the font. The -ascender and -descender methods, however, do take that
into account. So:
float height = [newFont ascender] + [newFont descender];
There's a nice layout chart that illustrates how the different font
metrics work together:
<file:///Developer/ADC Reference Library/documentation/Cocoa/
Conceptual/FontHandling/Tasks/GettingFontMetrics.html>
Also online:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
FontHandling/Tasks/GettingFontMetrics.html>
sherm--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden