Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS -- is it possible to force a UILabel subclass object to become the first responder?

Is there any way to do this?

I tried putting the following into the subclass:

- (BOOL)canBecomeFirstResponder 
{
    return YES;
}

But when I sent the object a becomeFirstResponder message, it still didn't become the first responder.

like image 799
William Jockusch Avatar asked Nov 03 '10 17:11

William Jockusch


1 Answers

Yes, it is possible. You should:

  1. Override becomeFirstResponder to return YES.

  2. Set userInteractionEnabled to YES.

  3. Add a UITapGestureRecognizer to handle taps.

  4. Call becomeFirstResponder from the tap handler.

You can even override inputView to get a input control at the bottom of the screen. Otherwise there will be nothing.

like image 178
Ivan Nikitin Avatar answered Oct 30 '22 11:10

Ivan Nikitin