Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8 Custom Keyboard

I am trying to build a custom keyboard, it's like a emoji keyboard, but the keyboard's data is from a json file. After parse this json file and get the data, how to make the custom keyboard use it and show in the keyboard view, like the emoji keyboard that built in? Right now, I follow App Extension Keyboard: Custom Keyboard guide, and there only small bits of information here. Is there any tutorial or guide about how to create a custom emoji keyboard online? The current codes I am trying are below:

class KeyboardViewController: UIInputViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        var error: NSError?
        let yanFile = NSBundle.mainBundle().pathForResource("yan", ofType: "json")
        let yanData = NSData(contentsOfFile: yanFile) as NSData
        let yanDict = NSJSONSerialization.JSONObjectWithData(yanData, options: NSJSONReadingOptions.MutableContainers, error: &error) as NSDictionary
        println("dict: \(yanDict)") //print nothing in console

        // Perform custom UI setup here
        self.nextKeyboardButton = UIButton.buttonWithType(.System) as UIButton

        self.nextKeyboardButton.setTitle(NSLocalizedString("Next Keyboard", comment: "Title for 'Next Keyboard' button"), forState: .Normal)

    }
}

The json like below:

{
    "list": 
    [
        {
            "tag": "laugh",
            "yan": 
            [
                "o(*≧▽≦)ツ┏━┓",
                "(/≥▽≤/)",
                "ヾ(o◕∀◕)ノ"
            ]
        },
        {
            "tag": "wanna",
            "yan": 
            [
                "✪ω✪",
                "╰(*°▽°*)╯",
                "≖‿≖✧",
                ">ㅂ<",
                "ˋ▽ˊ",
                "✪ε✪",
                "✪υ✪",
                "ヾ (o ° ω ° O ) ノ゙",
                "(。◕ˇ∀ˇ◕)",
                "(¯﹃¯)"
            ]
        }
    ]
}
like image 574
yong ho Avatar asked Jun 21 '14 09:06

yong ho


People also ask

How do I customize my keyboard on my iPhone 8?

Navigate to Settings > General > Keyboard > Keyboards > Add New Keyboard and select AC Custom Keyboard. This will add it to the list of available keyboards. Go back to your app and bring up the keyboard by tapping the text view. Tap and hold the globe key and select AC Keyboard from the list that pops up.

Does iOS have custom keyboard?

Add a Custom Keyboard Target to Your App Open your app project in Xcode. Choose File > New > Target. Select Custom Keyboard Extension from the Application Extension group.

Can you make a custom keyboard on iPad?

What to Know. Choose Settings > General > Keyboard > Keyboards > Add New Keyboard. Select the custom keyboard you want to use.


1 Answers

You can build a xib file by clicking new file -> view

1) inside the xib file create a uiview 320x216 and you can drag'n'drop whatever controls you want into it

2) then you can load the nib like this into your keyboard's inputView:

// Perform custom UI setup here
UIView *layout = [[[NSBundle mainBundle] loadNibNamed:@"keyboardXib" owner:self options:nil] objectAtIndex:0];
[self.inputView addSubview:layout];

3) i think it's amazing if you build a JSON to keyboard api you send a JSON of the keyboard map to your app and the app knows how to arrange the keys on the inputView accordingly

let us know if you build this project!

EDIT:

4) Most of what you need to do is parse the JSON and display the content you want from the JSON uibuttons, and also decide what text they are inserting into the text field

check out this question: How to parse a JSON file in swift?

Good luck!

like image 52
nurnachman Avatar answered Oct 13 '22 09:10

nurnachman