简体   繁体   中英

how to show different letters in textfield when clicking different buttons of keyboard in iOS

I am doing a keyboard by calling UIView and I have many buttons with different letters. I don't know how to get different letters in textfield because when I touch different button, it show the same letter in textfield. what is the code for telling that user touches the different button ?

All of the buttons should call the same IBAction.

Mine is called "-(IBAction)addCharacter:(id)sender".

Then you just do something like this:

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

That's the basics. Obviously if your keyboard needs to remove the last character, you will need to modify, but it should be easy to do using this base code.

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