Check if user has auto-correction enabled iOS - ios

I have a UITextView which has other views right at the bottom of it. I need to move the content of the text view up when auto-correction is enabled, so that the other views don't cover the little auto-correction window. However, if the pop-up windows never appears, it looks pointless to move the view up. Any suggestions?

You can check it by :
Swift 2.2
if textField.autocorrectionType == .Yes {
//do some stuff when auto correction is enabled
}
UITextField has a property autocorrectionType that is related with UITextAutoCorrectionType enum. AppleDocumentation about it:
//
// UITextAutocorrectionType
//
// Controls keyboard autocorrection behavior for a text widget.
// Note: Some input methods do not support inline autocorrection, and
// instead use a conversion and/or candidate selection methodology. In such
// cases, these values are ignored by the keyboard/input method implementation.
//

Related

Custom Keyboard extension with UITextField

I have custom keyboard extension with UITextField in it. I am able switch to UITextField's text input, but cannot switch back to self.textDocumentProxy. Does anybody know, how to do something like [self.textDocumentProxy becomeFirstResponder]?
(By the way, it looks like "GIF Keyboard" app provides such possibility)
I've implemented next workaround for this:
My textFied inherits from UITextField. UserInteraction disabled to prevent it from becomeFirstResponder (because you are not able switch back to system input). I've added blinking UIView as cursor imitation (blinking animation). Change this cursor origin.x in overwrited setText: method by calculating length of current string (use boundingRectWithSize: method for this).
When user types something I am checking if textField is active (showed) and then adding/removing symbols to textField (with setText:) or self.textDocumentProxy insertText:/deleteBackward methods accordingly.

iOS Custom keyboard can't return focus to app's textfield

I'm working on a custom keyboard for iOS which will have its own search field (similarly implemented by PopKey).
My keyboard's textfield is able to take the focus with becomeFirstResponder and I'm able to give it up by using resignFirstResponder. However after I resign focus, the host app has a difficult time retaking focus despite touching the form. The app's textfield will still show the text cursor blinking.
Any ideas? Thanks
The solution is a hack, as of right now you can't really give the host app its focus back.
Subclass a UITextField and on its delegate implement
textFieldShouldBeginEditing by returning NO.
Add a BOOL property isSelected that gets set to YES in touchesBegan (not to be confused with the default selected property)
In your keyboard's keyPressed method, if searchField.isSelected, manipulate the searchField.text. Else, manipulate textDocumentProxy like normal.
Add a clear button and method that wipes searchField.text and searchField.isSelected, allowing any further keystrokes to return to the textDocumentProxy
Add an animation that replicates the blinking type cursor

iOS Accessibility - is there a way to tell when VoiceOver has changed focus?

I'd like to call a method every time a different element is focused while VoiceOver is active. I was hoping there would be some UIAccessibilityNotification for this, but I can't seem to find any.
Ultimately, my goal is to add an additional condition prior to reading the accessibility label. For example, as opposed to saying (by default) "If UIButton becomes focused: read label", I'd like to be able to say "When UIButton becomes focused AND UIButton's background color is blue: read label".
So my question is: how do I either add an additional condition prior to reading the label, or receive a notification when a new element becomes focused?
You can't explicitly tell when the user moves the VoiceOver cursor (just like you can't tell where a sighted user is looking).
For the behavior you want, you have two options:
Set the button's accessibilityLabel to an appropriate value whenever the other conditions change.
Subclass UIButton and override its accessibilityLabel getter method:
- (NSString *) accessibilityLabel {
if (SOME_CONDITION) {
return #"Hooray!";
} else {
return #"Womp womp";
}
}
If you need to disable an item entirely, rather than returning nil or a blank string, you should set its accessibilityElementsHidden property to YES.
You can use the UIAccessibilityFocus protocol to detect changes in focus by accessibility clients (including VoiceOver). Note that UIAccessibilityFocus is an informal protocol that each accessibility element must implement independently.
That said, for your use case, Aaron is right to suggest returning a different accessibilityLabel under each condition.

How to use UITextField UIAppearance based on user Interaction enabled trait

I am trying to find a way to have UITextField appearance is distinguishable when user interaction is disabled. I have to do this application wide. Thought using UIAppearance could be an easy way to do. But couldn't figure out how to use that with user interaction enabled trait of text field.
Can you help? Or Is there an alternate way to do the same thing centrally.
Note: Text field user interaction enabled state on a given instance can get toggled based on user action.
Thanks
I don't know of an app wide way to do it if you're using text fields directly, but if you were to subclass UITextField and override setEnabled:, you could make a change to the background there.
#implementation MYTextField
- (void)setEnabled:(BOOL)enabled
{
[super setEnabled:enabled];
self.backgroundColor = [UIColor lightGrayColor];
}
#end
There is already a faint grey background for UITextFields which are disabled, but if this is not enough you can do more as above. Alternatively, you could use setDisabledBackground: on each UITextField to set an image for display when disabled - I accept that this isn't a great solution with the current design paradigms.

ios uibutton hidden: does this automatically make the button disabled?

I just have a knowledge question about UIButtons / iOS in general.
Let's say you have a UIButton. You set the 'hidden' property to YES. This makes it no longer visible in view, right? But I noticed that while it's no longer visible, it is also no longer clickable either. So, does this mean that setting hidden = YES also sets enabled = NO?
Just curious. Thanks y'all.
UIButton and all controls inherits common properties from UIView like hidden, backgroundColor, etc.
Class reference of UIView says if any view is hidden then it will not receive input events
Class reference of UIView says:
A hidden view disappears from its window and does not receive input
events. It remains in its superview’s list of subviews, however, and
participates in autoresizing as usual. Hiding a view with subviews has
the effect of hiding those subviews and any view descendants they
might have. This effect is implicit and does not alter the hidden
state of the receiver’s descendants.
you can find this over Here.
It does. Setting the buttons hidden property to YES will disable any user interaction. This is true for other UI elements as well as just UIButton.
Yes you can't touch button when it is hidden.If you wanna touch it then you must make it btn.hidden = NO;. Hidden means disable the user interaction.
Not sure. Best way to find out would be an NSLog returning button.hidden

Resources