Determine whether this field is complete on the page. Change the button status to iOS.

Source: Internet
Author: User

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];}

:

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.