您需要在更改字体大小后在大纲视图上调用 -setRowHeight:。例如 [outlineView setRowHeight:[font pointSize]+2.0]。
为了获得该行的最佳高度,这是我在我的应用程序中所做的:
CGFloat KBDefaultLineHeightForFont (NSFont *font, BOOL sizeForTextField)
{
if (font == nil)
font = [NSFont userFontOfSize:0]; // Use default system font if font is nil.
NSLayoutManager *lm = [[NSLayoutManager alloc] init];
if (sizeForTextField)
[lm setTypesetterBehavior:NSTypesetterBehavior_10_2_WithCompatibility];
// On Mountain Lion and above, string drawing is done without using screen fonts, so we must do the same.
if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_7)
[lm setUsesScreenFonts:NO];
CGFloat height = [lm defaultLineHeightForFont:font];
[lm release];
return height;
}
然后:
CGFloat rowHeight = MAX(16.0, KBDefaultLineHeightForFont(ovFont, YES) + 3.0);
[outlineView setRowHeight:rowHeight];
[[[[outlineView tableColumns] objectAtIndex:0] dataCell] setFont:ovFont];