iphone - UITextField > 强制光标停留在字段末尾

标签 iphone cocoa-touch uikit cursor uitextfield

用户不应该能够将 UITextField 的光标移动到输入字符串中的其他位置。

我需要这个,因为我希望用户输入货币金额。这是通过让用户输入将添加到金额末尾的数字来完成的,并且逗号将移动到从末尾算起的第三个位置。

如何强制 UITextField 中的光标停留在输入字符串的末尾?

最佳答案

UITextField 上放置一个 UIButton。将 IBAction 添加到按钮并让它调用 UITextField.becomeFirstResponder()

这可以防止点击传递、光标被修改,但仍然允许用户单击 View 并选择它。

关于iphone - UITextField > 强制光标停留在字段末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5361117/

相关文章:

iphone - cocoa - 数组不排序?

iphone - Xcode 看不到我的 iOS 设备,但 iTunes 可以

iphone - 将 NSPredicate 与字符串匹配

iphone - 如何在 iPhone View 中创建模糊文本?

ios - 撤消/重做以在 iOS 中绘图

ios - UIImageView 和自动布局

iphone - 尝试发送电子邮件,收到 "use of undeclared unidentified MFMailComposeViewController"

cocoa-touch - NSFileHandle fileHandleForWritingAtPath : return null!

ios - 在不结束回合的情况下更新 GKTurnBasedMatch 中的 matchData

ios - 删除动画后保留动画 UIView 属性,但不使用类变量?