Along with the superior tech specs iOS 8 has come up with an overwhelming list of features that made it stand ahead of its competitors. And, one of its interesting and fabulous features is that Apple has now enabled developers to launch their custom keyboards as app extension. Thereby, allowing users to choose their favorite custom keyboard (integrated in some application) and deploy it in other applications (that demands keyboard input) as well.
You can also reap the benefits of this amazing feature and create your application keyboard as an app extension. If you hire iPhone Application Development Services, you already gain a bona fide advantage. Here is a comprehensive guide to help you accomplish your task with ease.
In this article, we are considering the custom keyboard development as an app extension while deploying an Interface Builder document. This approach offers efficient results even if you are interested in creating a complex keyboard UI.
- First of all, create a new iPhone Simple View Application. You can give a desired name to this container app, like First Custom Keyboard. According to the Apple’s protocol, all the featured extensions and some functions must be included in this container app.
- Now, navigate to the project panel, select Project and click on Editor. After this, access the Add Target button and select iOS. Finally, select the Custom Keyboard as the Application Extension and click on the Next button.
- Rename the product as “First Keyboard” and click on “Finish” button.
- You can now insert the Text View to the main View and set it to the center.
To ensure that your keyboard is available in the list.
When the globe button is clicked from their default keyboard, a list of options will be represented. To add your keyboard to the list, you will need to make the following tweaks-
Navigate to the General Settings from the device and open the Keyboard options and click on Add New Keyboard option under the Keyboards tab. Now, from the available list of options simply choose your keyboard, here it is named as First Custom Keyboard.
By doing so, your custom keyboard will enter in the available list of keyboards. Select the globe button and switch to your keyboard.
After this, you get an empty screen boasting only a “Next Keyboard” button.
For adding desired keys in the keyboard via coding.
Access the KeyboardViewController.swift file and append the code for the Next Keyboard button in the viewDidLoad() method. This code will include the buttonTitles configuration, you may add a string of desired button titles that you want to view in your keyboard.
After doing this, create a function that will help you construct buttons for the titles added in the previous step. This function for creating buttons will need a string of titles as argument.
Once the appropriate buttons have been created, what’s left is defining the action to the buttons. Whenever a button is tapped, its corresponding keyPressed method will be called.
What’s next: Now, you will need to add constraints to the containingView and buttons, and this can be done efficiently via the method addConstraints(). You will need to pass two arguments to this method, one is buttons and another is the containingView.
Now, when you will run the keyboard after following all the four above mentioned steps properly, you can see the similar output on the screen as that is displayed in the image below.
Indubitably, you will get the desired result but the process is quite cumbersome. So, let’s move on to more convenient method, which can be accomplished via the Interface Builder document.
For adding desired keys in the keyboard via the Interface Builder document.
Go to File and create a New iOS File, and select the View option under the User Interface tab, by this you can create a nib file. Now, keeping the First Keyboard as the target, set the name of the file as Keyboard_View.
Make the following tweaks in the Attribute Inspector under the view of the nib file-
- Size = Freeform
- Status Bar = None
Under the Size Inspector, simply set-
- width = 300
- height = 200
Now, access the KeyboardViewController.swift file, add the following three lines of code after the call to super.viewDidLoad() method in the viewDidLoad() method in the file.
let nib = UINib(nibName: "Keyboard_View", bundle: nil) let objects = nib.instantiateWithOwner(self, options: nil) view = objects as UIView;
What’s next: In the main view of the nib file, via the Interface Builder document, click on Pin and give the desired values to the associated constraints. Make the appropriate tweaks by adding the requisite number of buttons to the view, assigning them a text color value and titles.
You can set the other constraints for each button separately by simply entering a suitable value in the document against the appropriate fields. Once you are done with all the tweaks, it is recommended to update the frame by clicking on Editor in the main menu, then selecting the Resolve Auto Layout Issues tap on the All Views button and choose Update Frames. After doing so, when you will execute your application, you can witness a similar interface as shown in the following image.
Similarly, you can add other requisite buttons and functions to its actions to integrate superior functionality in your keyboard. If you Hire Skilled iPhone Programmers of excellent caliber, they are well versed with the exercise.
Ensure an intuitive and highly interactive interface, which can help deliver improved user experience (UX) and thus, compel them to switch to this keyboard and abandon the built-in keyboard. With these simple steps you can conveniently create a custom keyboard for iOS devices.