Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8820105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:31:33+00:00 2026-06-14T05:31:33+00:00

I need to build a custom keyboard for my iPhone app. Previous questions and

  • 0

I need to build a custom keyboard for my iPhone app. Previous questions and answers on the topic have focused on the visual elements of a custom keyboard, but I’m trying to understand how to retrieve the keystrokes from this keyboard.

Apple provides the inputView mechanism which makes it easy to associate a custom keyboard with an UITextField or UITextView, but they do not provide the functions to send generated keystrokes back to the associated object. Based on the typical delegation for these objects, we’d expect three functions : one of normal characters, one for backspace and one for enter. Yet, no one seems to clearly define these functions or how to use them.

How do I build a custom keyboard for my iOS app and retrieve keystrokes from it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T05:31:35+00:00Added an answer on June 14, 2026 at 5:31 am

    Here’s my custom keyboard which I believe addresses these as completely as Apple will allow:

    //  PVKeyboard.h
    
    #import <UIKit/UIKit.h>
    @interface PVKeyboard : UIView
    @property (nonatomic,assign) UITextField *textField;
    @end
    
    //  PVKeyboard.m
    
    #import "PVKeyboard.h"
    
    @interface PVKeyboard () {
        UITextField *_textField;
    }
    @property (nonatomic,assign) id<UITextInput> delegate;
    @end
    
    @implementation PVKeyboard
    
    - (id<UITextInput>) delegate {
        return _textField;
    }
    
    - (UITextField *)textField {
        return _textField;
    }
    
    - (void)setTextField:(UITextField *)tf {
        _textField = tf;
        _textField.inputView = self;
    }
    
    - (IBAction)dataPress:(UIButton *)btn {
        [self.delegate insertText:btn.titleLabel.text];
    }
    
    - (IBAction)backPress {
        if ([self.delegate conformsToProtocol:@protocol(UITextInput)]) {
            [self.delegate deleteBackward];
        } else {
            int nLen = [_textField.text length];
            if (nLen)
                _textField.text = [_textField.text substringToIndex:nLen-1];
        }
    }
    
    - (IBAction)enterPress {
        [_textField.delegate textFieldShouldReturn:_textField];
    }
    
    - (UIView *)loadWithNIB {
       NSArray *aNib = [[NSBundle mainBundle]loadNibNamed:NSStringFromClass([self class]) owner:self options:nil];
       UIView *view = [aNib objectAtIndex:0];
       [self addSubview:view];
       return view;
    }
    
    - (id)initWithFrame:(CGRect)frame {
       self = [super initWithFrame:frame];
       if (self)
            [self loadWithNIB];
       return self;
    }
    @end
    

    In XCode 4.3 and later, you need to create an objective-Class (for the .h & .m files) based on UIView and a User Interface View file (for the .xib file). Make sure all three files have the same name. Using the Identity Inspector, make sure to set the XIB’s File’s Owner Custom Class to match the new object’s name. Using the Attributes Inspector, set the form’s size to Freeform and set the Status Bar to none. Using the Size Inspector, set the form’s size, which should match the width of the standard keyboard (320 for iPhone portrait and 480 for iPhone landscape), but you can choose any height you like.

    The form is ready to be used. Add buttons and connect them to the dataPress, backPress and enterPress as appropriate. The initWithFrame: and loadWithNIB functions will do all the magic to allow you to use a keyboard designed in Interface Builder.

    To use this keyboard with a UITextField myTextField, just add the following code to your viewDidLoad:

    self.keyboard = [[PVKeyboard alloc]initWithFrame:CGRectMake(0,488,320,60)];
    self.keyboard.textField = self.myTextField;
    

    Because of some limitations, this keyboard isn’t reusable, so you’ll need one per field. I can almost make it reusable, but I’m just not feeling that clever. The keyboard is also limited to UITextFields, but that’s mainly because of limitations in implementing the enter key functionality, which I’ll explain below.

    Here’s the magic that should allow you to design a better keyboard than this starter framework…

    I’ve implemented the only property of this keyboard, textField, using a discreet a discrete setter (setTextField) because:

    1. we need the UITextField object to handle the enter problem
    2. we need UITextField because it conforms to the UITextInput protocol which conforms to UIKeyInput, which does much of our heavy lifting
    3. it was a convenient place to set the UITextInput’s inputView field to use this keyboard.

    You’ll notice a second private property named delegate, which essentially typecasts the UITextField pointer to a UITextInput pointer. I probably could have done this cast inline, but I sensed this might be useful as a function for future expansion, perhaps to include support for UITextView.

    The function dataPress is what inserts text input the edited field using the insertText method of UIKeyInput. This seems to work in all versions back to iOS 4. For my keyboard, I’m simply using the label of each button, which is pretty normal. Use whatever NSStrings strike your fancy.

    The function dataBack does the backspace and is a little more complicated. When the UIKeyInput deleteBackward works, it works wonderfully. And while the documentation says it works back to iOS 3.2, it seems to only work back to iOS 5.0, which is when UITextField (and UITextView) conformed to the UITextInput protocol. So prior to that, you’re on your own. Since iOS 4 support is a concern to many, I’ve implemented a lame backspace which works on the UITextField directly. If not for this requirement, I could have made this keyboard work with UITextView. And this backspace isn’t as general, only deleting the last character, while deleteBackward will work properly even if the user moves the cursor.

    The function enterPress implements the enter key, but is a complete kludge because Apple doesn’t seem to give a method for invoking the enter key. So enterPress simply calls the UITextField’s delegate function textFieldShouldReturn:, which most programmers implement. Please note that the delegate here is the UITextFieldDelegate for the UITextField and NOT the delegate property for the keyboard itself.

    This solution goes around the normal keyboard processing, which hardly matters in the case of UITextField, but makes this technique unusable with UITextView since there is now way to insert line breaks in the text being edited.

    That’s pretty much it. It took 24 hours of reading and cobbling to make this work. I hope it helps somebody.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem: I need to build a custom tag, which can take
I have an ASP control custom built and I need to pass a value
I need to build app with user messages (dialogs). I've solved this problem by
I have an requirement to implement a custom keyboard for a Cocoa Touch data
I'm still not totally clear on why I would need to build custom action
I need to build a custom designed bar chart that displays some simple data.
I need to build some sort of a custom CMS for a client of
I need to build a library that is to be placed at a custom
I have build a custom PHP extension in C and included it in php.ini.
I need to build a visual editor in C#. Given a piece of PHP

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.