向文本字段的“左侧”添加填充 [英] Adding Padding To The 'left' of a Text Field

查看:98
本文介绍了向文本字段的“左侧”添加填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有背景的文本字段,但为了使它看起来正确,文本字段需要在其左侧有一些填充,像NSS​​earchField一样。如何在上为文本字段添加一些填充?

I have a text field with a background but to make it look right the text field needs to have some padding on the left side of it a bit like the NSSearchField does. How would I give the text field some padding on the left?

推荐答案

使用自定义NSTextFieldCell覆盖 drawingRectForBounds:。让它嵌入矩形,你想要多少,然后通过比新的矩形到[超级drawingRectForBounds:]得到正常的填充,并返回该调用的结果。

Use a custom NSTextFieldCell that overrides drawingRectForBounds:. Have it inset the rectangle by however much you want, then pass than new rectangle to [super drawingRectForBounds:] to get the normal padding, and return the result of that call.

这篇关于向文本字段的“左侧”添加填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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