由于某些原因,当我的按钮被禁用时,文本颜色变为白色。 我希望它保持黑色 - 我该怎么做?通过下拉菜单更改状态正常,高亮,残疾人等NSButton - 在禁用模式下设置文本颜色
你可以做,在Interface Builder:
由于某些原因,当我的按钮被禁用时,文本颜色变为白色。 我希望它保持黑色 - 我该怎么做?通过下拉菜单更改状态正常,高亮,残疾人等NSButton - 在禁用模式下设置文本颜色
你可以做,在Interface Builder:
可以为一个按钮的不同状态设置文本,图像,颜色,字体等。名单。
我无法在IB中找到此选项 – 2011-06-16 12:27:58
nsbutton颜色并非如此。 – 2012-04-20 13:15:04
@ErikSapir - 既然你接受了这个答案,我想你会发现IB在哪里。你可以和我们其他人分享吗? – pepsi 2012-05-29 20:21:49
你也可以继承NSButtonCell并重写的方法:
- (NSRect)drawTitle:(NSAttributedString *)title withFrame:(NSRect)frame inView:(NSView *)controlView
{
if (![self isEnabled]) {
return [super drawTitle:[self attributedTitle] withFrame:frame inView:controlView];
}
return [super drawTitle:title withFrame:frame inView:controlView];
}
这样,当按钮被禁用,文本将有文字相同颜色被启用按钮时。
还检查了该
[btnInfo.cell setImageDimsWhenDisabled:NO];
这适用于我。这是最好的答案。 – Mazyod 2013-08-13 03:29:22
不适用于我,文字颜色变暗 – 2014-11-10 23:41:18
您可以覆盖NSButtonCell的私有方法:
- (BOOL)_textDimsWhenDisabled {
return NO;
}
- (BOOL)_shouldDrawTextWithDisabledAppearance {
return NO;
}
我填补了雷达的公共方法:rdar:// 19218619
更新为迅捷4:
override func drawTitle(_ title: NSAttributedString, withFrame frame: NSRect, in controlView: NSView) -> NSRect {
if !self.isEnabled {
return super.drawTitle(self.attributedTitle, withFrame: frame, in: controlView)
}
return super.drawTitle(title, withFrame: frame, in: controlView)
}
这将使文本属性与启用按钮时相同。
你可能已经试过button.textcolor = [UIColor blackColor];但为了以防万一 – Radu 2011-06-16 12:01:22