简体   繁体   中英

How can I change name of button when I touch textField?

I know that it is a simple question, but I do not know how can I do that. I mean I need use gesture or some method and which one? I tried this with FirstResponder and touch events but all they are works not how I need. And title of button need to be changed only in one way - when I touch textField. Sorry for my english.

Use the UITextField Delegate :

-(void)textFieldDidBeginEditing:(UITextField *)sender{  
 //[sender resignFirstResponder];// Resigning the KeyBoard.
 [self.myButton setTitle:@"ddd" forState:UIControlStateNormal];
}

Try with below code:

[YourTextField addTarget:self 
                action:@selector(yourDesiredMethod) 
      forControlEvents:UIControlEventTouchUpInside];

-(void)yourDesiredMethod
{
    [YourButton setTitle:@"YourTitleString" forState:UIControlStateNormal];
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM