简体   繁体   English

触摸textField时如何更改按钮的名称?

[英]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. 我尝试过使用FirstResponder和touch事件,但是所有这些都无法满足我的需要。 And title of button need to be changed only in one way - when I touch textField. 而且按钮的标题仅需要以一种方式更改-当我触摸textField时。 Sorry for my english. 对不起我的英语不好。

Use the UITextField Delegate : 使用UITextField委托:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我在TextField中触摸时,如何在Xcode项目中禁用出现键盘的功能? - How can i disable in a Xcode project that a keyboard appears when i touch in a TextField? 用户触摸时如何更改精灵颜色 - How can I change a sprite color when user touch it 如何在 SwiftUI 中将 textField 键盘的“返回”按钮更改为蓝色的“完成”按钮? - How can I change the "Return" button of a textField keyboard to the blue "Done" button in SwiftUI? 如何更改 TextField 工具栏样式? - How Can I Change TextField Toolbar Style? 更改 textfield.text 属性时,如何检测 UITextField 中的更改? - How can I detect changes in UITextField when I change textfield.text property? iOS swift tableview触摸按钮时如何重新加载数据 - iOS swift tableview how can I reload the data when I touch button 当我按下按钮时如何更改UITableView的内容 - How i can change the content of a UITableView when i press a button 点击按钮时如何获得添加的行文本字段文本? - How can I get added row textfield text when tapping button? IOS Swift 这个按钮和文本域设计怎么做? - IOS Swift how can I do this button and textfield design? 如何将文本字段的值传递给Swift中的按钮单击函数? - How Can I Pass the Value of A Textfield to a Button Clicked Function in Swift?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM