[英]how to show different letters in textfield when clicking different buttons of keyboard in iOS
我正在通过调用UIView来做键盘,并且我有许多带有不同字母的按钮。 我不知道如何在文本字段中获取不同的字母,因为当我触摸不同的按钮时,它将在文本字段中显示相同的字母。 告诉用户触摸其他按钮的代码是什么?
所有按钮都应调用相同的IBAction。
我的被称为“-(IBAction)addCharacter:(id)sender”。
然后,您只需执行以下操作:
-(IBAction)addCharacter:(id)sender
{
//you can send an UIButton directly too.
UIButton *charBtn = (UIButton *)sender;
NSString *buttonPressed = charBtn.currentTitle.
//Your UITextField gets modified here.
//This method will append whatever button is pressed at the end of the string.
someTextField.text = [someTextField.text stringByAppendingString:buttonPressed];
}
这就是基础。 显然,如果键盘需要删除最后一个字符,则需要进行修改,但是使用此基本代码应该很容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.