Determine whether this field is complete on the page. Change the button status to iOS.
Check whether this field is complete on the page. Change the button status to iOS. In many development scenarios, there is some information to be filled in on the page, and then there is a button, when textFeild on the page is not complete, the button is not clickable. You can click it only after it is complete. How can this problem be achieved:
Because the textField entered on the page is not certain, I need to add a listening event for each textFeild. When the editing status changes, I can determine whether all textFeild values on the page already exist, if there is a value, the clickable status of the button is changed.
Since there may be many pages in the project that use the judgment method, we can encapsulate the method and directly retrieve it where it is used.
Code on (create a class, encapsulation method ):
// Determine whether there is a value. If there is NO, it will be gray. If yes, it will remain until the last one is yes, that is, yes + (void) setButtonStatusBytextFeilds :( NSArray *) textFeildArr button :( UIButton *) button {for (UITextField * textF in textFeildArr) {if (textF. text. length <= 0) {[button setBackgroundColor: kLineColor]; button. enabled = NO; return;} else {if ([(UITextField *) textFeildArr [textFeildArr. count-1] text]> 0) {[button setBackgroundColor: kGreenColor]; button. enabled = YES ;}}}}
In use:
// Add listening self for each textFeild. textFArr = @ [_ passordF, _ surePasswordF]; for (UITextField * textF in _ textFArr) {[textF addTarget: self action: @ selector (setBtnStatus) forControlEvents :( optional)];}
// Call the Judgment Method-(void) setBtnStatus {[ShowTool setButtonStatusBytextFeilds: _ textFArr button: _ registerBtn];}
: