iOS Turn on capitalization on UIKeyBoard temporarily? - ios

I need to manually turn caps lock on, on the keyboard.
Using autocapitalizationType property won't do the job. The problem is I am implementing a bullet list feature, where after the user inserts a bullet I need to turn on the capLock right away. This doesn't happen using standard autocapitalization because the first letter in my paragraph is #"•" rather than the text the user needs to enter.
Any way to turn capitalization on manually?

I had a similar issue a while back and what I ended up doing was using the UITextFieldDelegate or UITextViewDelegate depending on which control you are using they both contain textField:shouldChangeCharactersInRange:replacementString: or textView:shouldChangeCharactersInRange:replacementString: which is called every time the content of the field is changed. This allows you to change the character values automatically.
Hope this helps.
You can check out the documentation here: https://developer.apple.com/library/ios/documentation/uikit/reference/UITextFieldDelegate_Protocol/UITextFieldDelegate/UITextFieldDelegate.html#//apple_ref/occ/intfm/UITextFieldDelegate/textField:shouldChangeCharactersInRange:replacementString:

Related

Output specific images when user taps the keyboard

I want to output a image when a user taps on the keyboard. Let's say the user taps A on the keyboard in a UITextView. Instead of outputting the normal A, I want to output the picture of an Ape.
If a user taps "S" I want to output the image of a sun. Is this possible with out having to make a customized keyboard?
Besides creating a custom keyboard yourself, there isn't really a neat method to getting an image output.
One thing you could do is program Swift to automatically recognise the letter input and display an image over or replacing the letter as a result.
To do this, assign a variable to your editable UITextView or UITextField. If you are using XCode you can do this by control-dragging the text field into your code and it will automatically create a weak var, but you can change the strength in the pop up box that appears.
Since you now have a variable, there are two options as to how you display the image. One way is rather boring and will clutter your code, but essentially involves this, which I have simplified for the purposes of demonstration:
if UITextInput == a {
// add image
}
You would have to repeat this for every letter of the alphabet.
Or you could create a dictionary in which each letter corresponds to each image, and find a way to cycle through them, depending on the user's input. Even though this is harder to program for a newbie, it makes the code much neater and quicker.
This is the link to the official Apple documentation on dictionaries:
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/CollectionTypes.html#//apple_ref/doc/uid/TP40014097-CH8-ID113
However, since I assume you are programming an app for the younger market, I would recommend creating a custom keyboard as it will be easier in the long run.
Hope this helps,
will

IOS 8:custom Keyboard with undo and redo button

I have developed an IOS 8 custom keyboard. I want to give it "undo" and "redo" functionality, like the default system keyboard. I have tried it in different ways but was unable to find a good solution.
We can interact with a Text Input Object textDocumentProxy with the methods
insertText
deleteBackward
documentContextAfterInput
ocumentContextBeforeInput
But I was unable to find any way of implementing "undo" and "redo" functionality.
I think we can NOT implement these function (undo,redo)
According to https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/Keyboard.html
Because a custom keyboard can draw only within the primary view of its
UIInputViewController object, it cannot select text. Text selection is
under the control of the app that is using the keyboard. If that app
provides an editing menu interface (such as for Cut, Copy, and Paste),
the keyboard has no access to it. A custom keyboard cannot offer
inline autocorrection controls near the insertion point.
I think there are many case that content of textfield changed and you can not know when it changed, how it changed. If we can not know, we can not know to undo to where too. I think so.
I'm developing Custom keyboard extension like you and I have many problems. (eg: how can we know the current cursor to get current text selection...)
My question: Current text selection in CustomKeyBoardExtension (hope somebody know)

How to detect autocorrect state of UITextView?

How can I tell whether UITextView is in autocorrecting state? That is, the incorrect or incomplete part is highlighted and the candidate is popped up.
Neither selectedRange nor markedTextRange is useful for this.
I suppose you could force the autocorrect to be applied and then check to see if there are any changes (a modified version of this answer: https://stackoverflow.com/a/13012198/953105), however that will destroy the autocorrect suggestion. I'm not sure of your use case, but that could work.

Application freezes after editing custom UITextField

I have a custom UITextField used for validating for non empty input, correct emails, passwords bigger than x characters etc.
The UITextField has a delegate to itself, since I do all the validation on the text field object itself. Not sure if this is the problem.
This custom UITextField is created in the .XIB file.
The text field sometimes locks the application when editing the text field itself. It also usually locks up when I press the "Next" button on the keyboard (for going to the next text field that needs to be filled).
Xcode doesn't give back an error (such as a loop-error, which I was assuming it was), the application just locks up. This doesn't happen all the time, but usually, if I stress test it with text, then press "Next", it's likely to lock up.
The app doesn't crash...it doesn't go back to the main screen, but it really just locks up, and stays unresponsive.
Any ideas? Let me know if you need more info to figure this out. I'm at a loss at the moment.
edit: Solved, apparently it's not a good idea to set a UITextField's delegate to itself. What I ended up doing is creating a separate class that deals specifically as being the delegate for the UITextField and doing all the logic in that class. That class would also have a property connected to the text field it is a delegate for.
I'll also write the answer here:
Apparently it's not a good idea to set a UITextField's delegate to itself, because it can end up going into a loop.
What I ended up doing is creating a separate class that deals specifically as being the delegate for the UITextField and doing all the logic in that class. That class would also have a property connected to the text field it is a delegate for.

how do i make UIKeyInput make repeated deleteBackwards calls

Currently I am using UIKeyinput but it is only sending a single delteBackward event even when I hold down the delete key for a long time.
How can I make it send me multiple event calls when I hold delete down for a long time?
There is no easy way to have the system keyboard do auto-repeat. These leaves you with two options:
Fake it by using an overlay on the keyboard (see the comment by #pho0)
Implement a custom keyboard, install it as the inputView for your view or view controller and implement a custom protocol that supports auto-repeat.
Solution 1 works well if you only need the delete key to auto-repeat, but if you need all the keys to auto-repeat the overlay code becomes as complex as the custom keyboard option. (The overlay needs a rectangle for each key, so why not just replace the underlaying keyboard).
Solution 2 involves a certain amount of "up-front" work... One way you might do this is define a key cap class (like a physical key) and a keyboard layout class.
I have implemented both solutions in projects I have worked on, but I currently use solution 2 since I can create whatever keyboard I like. In the simple case the use need never know that it is not the system keyboard. For power users they can customize the keyboard as they see fit.
For what it is worth, I found it useful to have the keyboard class be dumb; it just communicates that a key has transitioned to being down or has transitioned to being up. An additional class above that decides what action should be taken.
In some ways, I know this is not the answer you were looking for, but I hope it helps,
IDZ
One thing I've seen people do is put a fake button on top of the keyboard button. When someone is holding down on it, have a timer remove the last letter every time it fires.
Hope this helps.

Resources