gpt4 book ai didi

swift - NSTextfield 的背景色

转载 作者:可可西里 更新时间:2023-11-01 00:56:22 28 4
gpt4 key购买 nike

我使用 NSTextfield 作为标签。我尝试像这样更改 backgroundColor

let myLabel = NSTextField(labelWithString: "A Label")
myLabel.backgroundColor = NSColor.green

但它不起作用。出了什么问题?

最佳答案

您需要将 NSTextFielddrawsBackground 设置为 true。此 boolean 控制接收器的单元格是否在其文本后面绘制背景颜色。

let myLabel = NSTextField(labelWithString: "A Label")
myLabel.drawsBackground = true
myLabel.backgroundColor = NSColor.green

来自 Apple Documentation :

In order to prevent inconsistent rendering, background color rendering is disabled for rounded-bezel text fields.

关于swift - NSTextfield 的背景色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46837475/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com