Disabling keys on keyboard

前端 未结 3 1481
栀梦
栀梦 2021-02-04 15:22

I am new to Objective-C, and I am looking to limit a user from switching from the alphabet portion of a normal keyboard to the numeric/punctuation side. This being said, I would

3条回答
  •  伪装坚强ぢ
    2021-02-04 16:04

    You actually can add and remove buttons of the default UIKeyboard

    There's some recipes on the Internet like this: http://www.iphonedevsdk.com/forum/iphone-sdk-development/6573-howto-customize-uikeyboard.html and like this: http://www.iphonedevsdk.com/forum/iphone-sdk-development/6275-add-toolbar-top-keyboard.html

    Those posts show you how to add a button, however the same principle can be used to remove.

    Below I'll show you a compilation of one of the solutions:

    //The UIWindow that contains the keyboard view - 
    //It some situations it will be better to actually
    //iterate through each window to figure out where the keyboard is, 
    // but In my applications case
    //I know that the second window has the keyboard so I just reference it directly
    //
    UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] 
    //                     objectAtIndex:1];
    
    //Because we cant get access to the UIKeyboard throught the SDK we will 
    // just use UIView. 
    //UIKeyboard is a subclass of UIView anyways
    UIView* keyboard;
    
    //Iterate though each view inside of the selected Window
    for(int i = 0; i < [tempWindow.subviews count]; i++)
    {
        //Get a reference of the current view 
        keyboard = [tempWindow.subviews objectAtIndex:i];
    
        //Check to see if the className of the view we have 
        //referenced is "UIKeyboard" if so then we found
        //the keyboard view that we were looking for
        if([[keyboard description] hasPrefix:@"

提交回复
热议问题