我可以在UITextField上设置插入点(Can I set the insertion point on a UITextField)

编程入门 行业动态 更新时间:2024-10-27 03:30:13
我可以在UITextField上设置插入点(Can I set the insertion point on a UITextField)

我有一个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).

更多推荐

本文发布于:2023-07-22 19:23:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1222720.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:set   UITextField   point   insertion

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!