Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 TextField,我只希望最终用户输入货币值,例如 20000。我希望该字段自动显示带有显示掩码的输入数字,以便当用户输入击键时它会更改字段内容动态的。例如,输入的 2000050 将显示为 20,000.50。
您使用
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string`
委托方法。在方法中查看当前字符串是什么(textField.text),应用替换字符串后会是什么,然后创建您自己的格式化字符串并使用 textField.text = "20,000.50" 等设置它。自处理后返回 NO文本。