Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Custom Keyboard Extension auto capitalization

I have designed a custom keyboard extension and I am able to enter text properly. However I can't seem to be able to figure out when to enable a capitalized keyboard and when lowercase. This is mostly because the following functions don't correctly return the already entered before/after text. Sometimes they will return nil, sometimes only a last few characters etc. Many times these methods are not even called at all.

- (void)textWillChange:(id<UITextInput>)textInput 

- (void)textDidChange:(id<UITextInput>)textInput

I have figured out the following scenarios when I need to have enable my uppercase keyboard:

  1. Text length =0 or nil
  2. When a period is entered, I need to add a space and uppercase keyboard
  3. When the cursor is placed at a location where the character before cursor is either a period or a space and before that is a period.
  4. When user selected the entire text "Select All"
  5. When user selected the entire text and deleted all
  6. When user backspaces and the new character before cursor is either a period or a space and before that is a period.
  7. When user pastes text and the character before cursor is either a period or a space and before that is a period.

Also if the above is possible, is it possible to also get the last entered "entire" word which I can use for dictionary searches like for predictive typing?

I have read the apple document where it states that users expect auto-capitalization, so I am sure this should be possible

https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html

like image 575
sudoExclaimationExclaimation Avatar asked Jan 02 '16 22:01

sudoExclaimationExclaimation


People also ask

How do I make my lowercase type automatically?

To use a keyboard shortcut to change between lowercase, UPPERCASE, and Capitalize Each Word, select the text and press SHIFT + F3 until the case you want is applied.

Can you make custom keyboards on iPhone?

A bevy of apps let you redesign your keyboard. Typewise arranges the keys into an easier-to-type honeycomb shape, while apps like Microsoft's SwiftKey let you type by swiping from key to key (a feature iOS has since adopted) and use a different text prediction tool.


1 Answers

E.G. textField being named of your UITextField instance. Put this after initializing.

textField.autocaptializationType = UITextAutocapitalizationTypeSentences

That should give you capital letters in all of the instances you mentioned.

Ok to make your custom keyboard adopt UITextInputTraits protocol, do the following.

@interface MyCustomKeyboard : UITextInput <UITextInputTraits> //Now adopts the UITextInputTraits protocol.

 - (instancetype)init {
     self = super.init;

     if(self) {
         //Here you can set the properties that come with the protocol
         self.autocapitilizationType = UIAutocapitalizationTypeSentences;

      }
}
like image 88
NSGangster Avatar answered Oct 03 '22 00:10

NSGangster