UITextField的文本插入? [英] Text inset for UITextField?

查看:81
本文介绍了UITextField的文本插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想插入一个UITextField的文本。这可能吗?感谢。

I would like to inset the text of a UITextField. Is this possible? Thanks.

推荐答案

覆盖 -textRectForBounds:占位符文本。要更改可编辑文本的内容,您还需要覆盖 -editingRectForBounds:

Overriding -textRectForBounds: will only change the inset of the placeholder text. To change the inset of the editable text, you need to also override -editingRectForBounds:

// placeholder position
- (CGRect)textRectForBounds:(CGRect)bounds {
     return CGRectInset(bounds, 10, 10);
}

// text position
- (CGRect)editingRectForBounds:(CGRect)bounds {
     return CGRectInset(bounds, 10, 10);
}

这篇关于UITextField的文本插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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