Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
636 views
in Technique[技术] by (71.8m points)

objective c - Customizing the iPhone keyboard

Is there a way to modify or make your own iPhone keyboard so that you can type in unsupported languages?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can create your own keyboard, but actually using it is more difficult.

To create it:

  1. Create the keyboard view. You can use whichever subviews you want. The most useful way to do this is probably to create a UIView subclass.
  2. Arrange for an instance of your keyboard view to be returned by any UIResponder's inputView property. For UITextView and UITextField, this is as simple as assigning the property; for other classes, you will probably have to subclass or swizzle the accessors as the property is declared read-only by default.

More details on this are available in the documentation.

Unfortunately, actually using this custom keyboard is more difficult. As of iOS 4.3, neither UITextField nor UITextView conform to the UITextInput protocol, which would be ideal for this purpose. For UITextView you should be able to make it work using the methods provided by the class, but since UITextField doesn't give any way to find the current selection or cursor position you won't be able to create a fully-functional keyboard using publicly-documented methods (append and delete-from-end are possible, and even inserting at the current position by manipulating the clipboard, but a "delete previous character" button like that on the standard keyboard will prove impossible).

As of iOS 5.0, UITextField and UITextView finally do implement the UITextInput protocol. It should now be a simple matter to insert and delete text at the cursor position.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...