开发者

Custom iPad keyboard that looks like the system keyboards

开发者 https://www.devze.com 2023-01-10 00:01 出处:网络
I\'m looking for a non-hackish solution for this, so basically -inputView.The part that I\'m not sure about is how 开发者_Go百科to make it look like the regular keyboards, from the background to the k

I'm looking for a non-hackish solution for this, so basically -inputView. The part that I'm not sure about is how 开发者_Go百科to make it look like the regular keyboards, from the background to the keys. I realize that I could photoshop an apple keyboard, but this seems like it is a little hackish, especially if apple (probably not but still possible) decides to change the look of their keyboards. I know Numbers has done an excellent job of making extra keyboards that look like the standard system ones, and I would like to do it like those (although obviously they have access to the same resources that made the system keyboards, including possible private frameworks, etc.)


I used the following:

tenDigitKeyboard.m

-(IBAction)pressedKey:(UIButton *)sender
{
    [delegate pressedKey:sender.tag];
}

where delegate is defined as `id delegate;

then in the delegate i do...

-(void)pressedKey:(NSInteger)key
{
    NSString * bufferString = model.string;
    if (key == -1) {//delete
        model.string = [bufferString substringWithRange:NSMakeRange(0, [bufferString length]-1)];
    }else{
     //will need to change the following to lookup key value based on a lookup of the button.tag
        model.string = [bufferString stringByAppendingFormat:@"%i",key];
    }
    [self update];//updates the view
}

I got the keyboard button artwork from: http://www.teehanlax.com/blog/iphone-gui-psd-v4/


Create a view controller and xib. The xib should have 1-9,0 and delete buttons mapped to IBOutlets in your controller. Store and retain the return value string as a property. You can add decimals, etc. if you wish. In the header, store an edition block closure with a property (or alternatively create a delegate or use notification).

@property (copy) void(^valueChangedBlock)(NSString* string);

On touch up, each button sends an event to a method like this:

- (IBAction) pressKey:(id)sender
{
    NSString *toAppend;

    // Instead of this switch you can store the values in a dictionary mapped by sender.
    switch(sender)
    {
        case oneButton: toAppend=@"1"; break;
        case twoButton: toAppend=@"2"; break;
        ...
    }

    returnValue = [returnValue appendString:toAppend];
    valueChanged(returnValue);
}

Obviously the delete key should remove a character from the end of the string instead of appending. Other than creating the controller and adding this view as the inputView, you should add the valueChangedBlock and set it to update the text field. You may want to put a clear custom button over the text field set to make the field first responder so it doesn't appear as if the user can edit at any point in the string.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号