Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么设置小数点只能输入后两位 #50

Open
jiangyongjian opened this issue Nov 24, 2020 · 6 comments
Open

怎么设置小数点只能输入后两位 #50

jiangyongjian opened this issue Nov 24, 2020 · 6 comments

Comments

@jiangyongjian
Copy link

怎么设置小数点只能输入后两位

@jiangyongjian
Copy link
Author

  • (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string 这个方法什么时候暴露出来

@matmartinez
Copy link
Owner

@jiangyongjian sorry, I can only provide support if you write this in English (or Spanish!).

@jiangyongjian
Copy link
Author

How to set the decimal point can only input the last two digits

@jiangyongjian
Copy link
Author

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string; Can we expose a method similar to this

@matmartinez
Copy link
Owner

matmartinez commented Nov 26, 2020

Hey @jiangyongjian! You can implement that functionality by adopting the MMNumberKeyboardDelegate protocol. You should take a look at this method:

- (BOOL)numberKeyboard:(MMNumberKeyboard *)numberKeyboard shouldInsertText:(NSString *)text;

You’ll notice the method is very similar to the one you are mentioning from UITextFieldDelegate, although it doesn’t include a range. This is because input views (like this keyboard) are generic and don’t know about the implementation nature of the receiver (it may or not be a editing view that supports ranges).

So, if you’re using an UITextField, you can just grab the current range from the text field directly, and implement your logic accordingly.

Hope it helps!

@matmartinez matmartinez reopened this Nov 26, 2020
@jiangyongjian
Copy link
Author

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants