我有一个UITextField,我希望以预先填充的后缀呈现给用户。 显然,我想将插入点设置为预填充文本的开头。
对我来说,如何做到这一点似乎并不明显(没有insertPoint属性),但有一种棘手的方法来完成这项工作吗?
I have a UITextField that I want to present to the user with a pre-filled suffix. Obviously, I'd like to have the insertion point set to the beginning of the pre-filled text.
It doesn't seem obvious to me how to do this (there's no insertionPoint property), but is there a tricky way to get this done?
最满意答案
覆盖drawTextInRect:以始终绘制后缀,即使它未包含在UITextFields文本中(使用带有textfield.text的临时字符串,附加后缀并绘制它)。 用户完成编辑后,将后缀附加到字符串(如果有帮助,则单独使用它们)。
Override drawTextInRect: to always draw your suffix, even though it is not contained in the UITextFields text (use a temp string that takes the textfield.text, appends your suffix, and draws it). Once the user is done editing, then append your suffix to the string (or use them separately if it helps).
更多推荐
发布评论