5
如何設置NSButtonCell標籤(標題)文本的顏色,即表格視圖的列單元格的顏色?就我而言,它是一個複選框按鈕單元格。 (是否可以使用IB?)如何設置NSButtonCell文本標籤的顏色
如何設置NSButtonCell標籤(標題)文本的顏色,即表格視圖的列單元格的顏色?就我而言,它是一個複選框按鈕單元格。 (是否可以使用IB?)如何設置NSButtonCell文本標籤的顏色
您可以嘗試屬性字符串值。
NSColor *txtColor = [NSColor redColor];
NSFont *txtFont = [NSFont boldSystemFontOfSize:14];
NSDictionary *txtDict = [NSDictionary dictionaryWithObjectsAndKeys:
txtFont, NSFontAttributeName, txtColor, NSForegroundColorAttributeName, nil];
NSAttributedString *attrStr = [[[NSAttributedString alloc]
initWithString:@"Hello!" attributes:txtDict] autorelease];
[[attrStrTextField cell] setAttributedStringValue:attrStr];
[attrStrTextField updateCell:[attrStrTextField cell]];
試試這個,我認爲它是完美的。
NSColor *color = [NSColor redColor];
NSMutableAttributedString *colorTitle =
[[NSMutableAttributedString alloc] initWithAttributedString:[button attributedTitle]];
NSRange titleRange = NSMakeRange(0, [colorTitle length]);
[colorTitle addAttribute:NSForegroundColorAttributeName
value:color
range:titleRange];
[button setAttributedTitle:colorTitle];
您可以通過'0.0'大小來獲得默認的常規大小。您還可以向NSFont詢問任何其他尺寸(例如,小控件和單元格的尺寸)。你通常不應該傳遞一個明確的大小。 – 2010-10-14 15:53:22