NSButton删除文本阴影

时间:2013-03-19 02:25:56

标签: cocoa text colors shadow nsbutton

我使用带有自定义背景的标准NSButton。黑色标题颜色有白色阴影 - 我该如何删除它?

图像: http://i.piccy.info/i7/f4ae52b56aad922f0129e4b6bd8688da/4-57-36/57765457/Snymok_ekrana_2013_03_19_v_04_13_58.png

1 个答案:

答案 0 :(得分:3)

解决!

NSAttributedString文档说NSShadowAttributeName的默认值为nil,但在这种情况下,按钮标题是用白色阴影绘制的。透明阴影解决了问题:

NSShadow *shadow = [[NSShadow alloc] init];
[shadow setShadowColor:[NSColor colorWithDeviceWhite:1.0 alpha:0.0]];

NSDictionary *attrsDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                                 shadow, NSShadowAttributeName, nil];

NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:_customTitle attributes:attrsDictionary];

[mybutton setAttributedTitle:attrString];