Xcode 6 Swift WKWebView keyboard settings

后端 未结 2 1133
醉话见心
醉话见心 2021-02-15 05:17

I\'m using a WKWebView to load a website and everything is working fine. However, I do not have access to the keyboard properties the same way I do with a textfield. Can someone

2条回答
  •  温柔的废话
    2021-02-15 05:30

    The Text Programming Guide for iOS, has a section called Configuring the Keyboard for Web Views that states the following:

    Although the UIWebView class does not support the UITextInputTraits protocol directly, you can configure some keyboard attributes for text input elements. For example, you can include autocorrect and autocapitalize attributes in the definition of an input element to specify the keyboard’s behaviors, as shown in the following example.

    
    

    You can also control which type of keyboard is displayed when a user touches a text field in a web page. To display a telephone keypad, an email keyboard, or a URL keyboard, use the tel, email, or url keywords for the type attribute on an input element, respectively. To display a numeric keyboard, set the value of the pattern attribute to "[0-9]*" or "\d*".

    These keywords and the pattern attribute are part of HTML 5 and are available in iOS. The following list shows how to display each type of keyboard, including the standard keyboard.

    Text:
    Telephone:
    URL:
    Email:
    Zip code:

    That, of course, only solves some very specific problems in a limited number of situations, but as far as I know that's all we've got to work with, even with WKWebView.

    I would love for someone to prove me wrong and let us know how to add a keyboard accessory view, or change the appearance of the keyboard when it's focused on a form element inside a web view in an iOS app.

提交回复
热议问题