我正在使用 WKWebView 加载网站,一切正常。但是,我无法像使用文本字段那样访问键盘属性。有人能给我指点一些资源,帮助我访问网络上键盘的属性(通过图形用户界面或编程方式)吗?
最佳答案
Text Programming Guide for iOS , 有一个名为 Configuring the Keyboard for Web Views 的部分声明如下:
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
andautocapitalize
attributes in the definition of an input element to specify the keyboard’s behaviors, as shown in the following example.<input type="text" size="30" autocorrect="off" autocapitalize="on">
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
,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:
<input type="text"></input>
Telephone:<input type="tel"></input>
URL:<input type="url"></input>
Email:<input type="email"></input>
Zip code:<input type="text" pattern="[0-9]*"></input>
当然,这只能在有限的情况下解决一些非常具体的问题,但据我所知,即使是 WKWebView
,我们也只能解决这些问题了。 .
我希望有人能证明我是错的,并让我们知道如何添加键盘附件 View ,或者在 iOS 应用程序中将焦点放在 Web View 内的表单元素上时更改键盘的外观。
关于ios - Xcode 6 Swift WKWebView 键盘设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26872450/