UITextField shows the cursor even if userInteractionEnabled is set to NO

I have a UITextField and it should still blink with the cursor, even its userInteractionEnabled property is set to NO. I do not want the UITextField to become FirstResponder and show the keyboard.

Now you can ask:

1. If you want to hide the keyboard, why show the cursor?

A: The problem is that I need to show the user that the UITextField is being edited with a different / user keyboard.

2. So why aren't you using the inputView property?

A: Since the keyboard in the inputView appears at the bottom, and I want my custom keyboard to be in the center of the screen.

So open the real question:

How can I show the cursor? Is there any property that I can set? If not, how would I draw a cursor? Creating a UIView that is added and removed using alpha or a subclass of UITextField and overrides drawInRect?

0
source share
1 answer

You can add a small UIView with a relay animation that sets the alpha value to 0 and 1 back and forth using animateWithDuration:delay:options:animations:completion:

 [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionRepeat animations:^{ [cursorView setAlpha:0]; } completion:^(BOOL animated){ [cursorView setAlpha:1]; } ]; 

To correctly position the view as a subfield of a text field, you can use the NSString sizewithfont:forWidth:lineBreakMode: method before the entered text sizewithfont:forWidth:lineBreakMode:

+3
source

All Articles