"Get verification code" and "get verification code"
When it comes to the user registration function, many apps now use mobile phone numbers as the basis for registration, which naturally cannot be separated from mobile phone verification codes. To prevent repeated clicks, a countdown is usually displayed. After a user clicks the button, the button becomes grayed out, and is displayed xx seconds later. After the countdown, the button is restored.
It is not difficult to implement it. You can use NSTimer or GCD for timer. But there are several things to note:
1. About the control selection, is it UIButton or UILabel?
On the surface, it seems that the UIButton implementation should be very simple. The UIButton itself has a click event, and the second is to control the UIButton color and whether it can be clicked (userInteractionEnabled. However, when the countdown starts, the UIButton text changes every second will flash (the screen should be supplemented by your own brain ).
Therefore, I chose UILabel to add a tap gesture to it to implement click events. The disadvantage is that there is no click feedback effect.
2. After a user clicks get verification code, the user returns (the view is pop or dismiss), and then enters the view (push or present). The "get verification code" status becomes clickable again, there is still the possibility of repeated clicks in a short time. In this case, it is hard to say that he has a vulnerability, but some people may think it is very serious.
If it is unfortunate that this group has your leader, product manager, or tester (I am an unfortunate group, you have to fix this "bug ".
I have implemented the above functions and encapsulated the relevant code into a tool class. The code is put on github. Here is the link.
The final results are as follows: