Re: Set TableView font and rowHeight
Re: Set TableView font and rowHeight
- Subject: Re: Set TableView font and rowHeight
- From: Ivan C Myrvold <email@hidden>
- Date: Mon, 2 Apr 2007 12:53:28 +0200
I suppose you mean
NSRect brect = [[self newFont] boundingRectForFont];
float height = brect.size.height + [newFont ascender] + [newFont
descender];
This makes the NSTableView showing OK in large font sizes, but the
row heights are too large in small font sizes.
Ivan
Den 2. apr. 2007 kl. 12.28 skrev Sherm Pendley:
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