如何将TextField的Float内容类型放在XCode上?

时间:2018-08-13 12:51:49

标签: ios xcode uitextfield content-type

我要给用户一个TextField放置一个数字值(浮点数或双精度数),但是在大多数情况下,该数字为整数,但是我必须以浮点数格式显示该值,例如:/usr/local/opt/node@8/bin,{{ 1}}。当用户放置一个Integer时,该值显示为:3.0。如何设置TextField自动放入小数点值的方法? ps。在内容选项中,没有数字选项。

enter image description here

这是错误的方式:

enter image description here

1 个答案:

答案 0 :(得分:0)

没有收件箱解决方案,您应该使用UITextFieldDelegate手动完成此操作:

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
   //customize your string here
}
相关问题