未调用UITextField上的drawTextInRect [英] drawTextInRect on UITextField not called

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

问题描述

我正在尝试实施这个问题的答案。问题是: - [drawTextInRect] 显然没有被调用,并在 - [drawRect] 中设置阴影不会使得UITextField的文本被遮蔽。

I'm trying to implement the answer to this SO question. The problem is: -[drawTextInRect] is apparently not called, and setting the shadow in -[drawRect] doesn't make the UITextField's text shadowed.

另一个奇怪的事情是即使我的子类实现 - [drawTextInRect] - [drawRect] 是完全空的(甚至不是对super的调用),会绘制文本字段的文本。

Another weird thing is that even if my subclass implementations of -[drawTextInRect] and -[drawRect] are completely empty (not even a call to super), the textfield's text is drawn.

推荐答案

这是 UITextField API文档中的错误。该文档表明覆盖 drawTextInRect:可用于自定义行为。情况并非如此。

This is a bug in the UITextField API documentation. The documentation indicates that overriding drawTextInRect: can be used to customize behaviour. This is not the case.

事实上, drawTextInRect:永远不会在 UITextField ( drawPlaceholderInRect:也不会被调用)。

In fact, drawTextInRect: will never be called on an UITextField (drawPlaceholderInRect: will be called neither by the way).

参见还 http://discussions.apple.com/thread.jspa?threadID=1727596

覆盖 UILabel 上的方法有效。

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

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