为 NSTextField 设置边框 [英] Set border for NSTextField
问题描述
哇,我真的掉进了兔子洞.我试图在 UI 的一部分和文本字段的背景上添加文本作为另一部分,例如生日在:
Wow, I've really fallen down the rabbit hole. I'm trying to have text on the background of part of a UI and a text field as another part, e.g. the birthday in:
然后我想重新利用提交的文本以允许文本输入.所以我做了类似的事情:
I then want to repurpose that text filed to allow text entry. So I do something like:
myTextFieldName.editable = true
myTextFieldName.backgroundColor = NSColor.textBackgroundColor()
我得到类似的信息:
这一切都很好,但后来我注意到它下面的文本字段周围有漂亮的细边框.所以我想,我需要一个边界!我添加一个:
Which is all well and good, but then I note the nice thin border around the text field below it. So I think, I need a border! I add one with:
myTextFieldName.bordered = true
...我得到:
哇!多么可怕的奇怪粗边框!它看起来根本不像默认的文本字段边框!在我的一生中,我无法弄清楚如何使我的激活"文本字段的边框与默认值相匹配.有什么想法吗?
Pow! What a hideous strange thick border! It doesn't look like the default text field border at all! For the life of me, I can't figure out how to make the border of my "activated" text field match that of the default. Any ideas?
非常感谢!
推荐答案
需要设置边框和边框颜色:
Need to set border and border color:
myTextFieldName.wantsLayer = true
myTextFieldName.layer?.borderColor = NSColor(red:204.0/255.0, green:204.0/255.0, blue:204.0/255.0, alpha:1.0).cgColor
myTextFieldName.layer?.borderWidth = 1.0
myTextFieldName.layer?.cornerRadius = 0.0
如果您想要圆角,请设置圆角半径.
Set corner radius if you want rounded corner.
这篇关于为 NSTextField 设置边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!