objective-c - OSX - 如何更改 NSButton 标题颜色

标签 objective-c cocoa

我的项目有按钮以及默认标题颜色为黑色的复选框,我想将标题颜色更改为红色

最佳答案

以下是在 Controller 中设置按钮标题颜色的代码:

 NSColor *color = [NSColor greenColor];
 NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
 [style setAlignment:NSCenterTextAlignment];
 NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
 color, NSForegroundColorAttributeName, style, NSParagraphStyleAttributeName, nil];
 NSAttributedString *attrString = [[NSAttributedString alloc]
 initWithString:@"Title" attributes:attrsDictionary];
 [self.button setAttributedTitle:attrString];

也许这就是你想要的。

关于objective-c - OSX - 如何更改 NSButton 标题颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34993761/

相关文章:

ios - 我如何解决 iPhone 4 5 6 6+ 中的图像自动调整大小问题

cocoa - 如何在绘制 NSPopUpButton 单元格时手动突出显示它(使用白色而不是黑色绘制)?

Cocoa:获取 NSStatusBar 项目的位置

cocoa - 如何更改默认帮助不可用消息

ios - 从 .dae 加载 SCNScene 时的物理问题

ios - 第二次添加/删除断言失败

ios - 在 UILabel 中显示分数

iphone - Autolayout 使 ScrollView 中的 ImageView 不可滚动

macos - 退出 xcode cocoa swift 应用程序

objective-c - 关于删除对象索引