NSTextField的边距和填充? (迅速) [英] NSTextField margin and padding? (Swift)

查看:307
本文介绍了NSTextField的边距和填充? (迅速)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以为NSTextField设置边距或填充?

I am wondering if there’s a possibility to set a margin or padding for NSTextField?

我实现了一个或多或少自定义外观的textField(此屏幕快照中的第一个)...

I achieved a more or less custom looking textField (the first one in this screenshot)...

...使用此代码:

myTextField.wantsLayer = true
myTextField.layer?.cornerRadius = 2.0
myTextField.layer?.borderWidth = 1.0
myTextField.layer?.borderColor = CGColor(red: 0.69, green: 0.69, blue: 0.69, alpha: 1.0)

但是,感觉就像我必须在左侧添加一些填充以使数字不太靠近边框.那有可能吗?

However, it feels like I have to add some padding on the left side so that the numbers are not too close to the border. Is that even possible?

推荐答案

我通常只是通过将textField放在容器视图中来执行此操作.您可以为视图提供所需的任何拐角半径,边界等,然后仅使用所需的填充将textField约束在内部.只需确保将textField的边框样式更改为"none",否则您就可以在视图中看到它.

I usually do this just by putting the textField in a container view. You can give the view any corner radius, border, etc you want, and then just constrain the textField to the inside with whatever padding you want. Just make sure you change the textField's border style to 'none' or you'll be able to see it inside your view.

也许可以像使用按钮一样更改内容插图,但是我从来没有找到它.

There might be a way to change the content inset like you can with a button, but I've never been able to find it.

这篇关于NSTextField的边距和填充? (迅速)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆