feb*_*ing 5 macos cocoa objective-c
如何设置NSButtonCell标签(标题)文本的颜色,即表格视图的列单元格?就我而言,它是一个复选框按钮单元格.(有可能使用IB吗?)
Muh*_*wan 12
尝试这个,我认为它是完美的.
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];
Run Code Online (Sandbox Code Playgroud)
您可以尝试使用属性字符串值.
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]];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9961 次 |
| 最近记录: |