简体   繁体   中英

UITExtField in not getting focus on tapping

I have created a subclass (TextFieldSubClass)of UITextField, below is the code

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
   [UIMenuController sharedMenuController].menuVisible = NO;
//    if (action == @selector(paste:))
//        return YES;
//    if (action == @selector(select:))
//        return YES;
//    if (action == @selector(selectAll:))
//        return YES;
    return NO;
}

- (BOOL)canBecomeFirstResponder
{
    return  true;
}
- (CGRect)caretRectForPosition:(UITextPosition *)position
{

    return CGRectZero;
}

And in other class i am adding a textfields on XIB and setting textfields class to TextFieldSubClass in properties window

When i am tapping on this text field then its not getting focus, its cursor is not showing but am able to enter ext in it.

Even when i am tapping on textfield then its delegates are not being called, but delegate are called for other textfield that are of type UITextField

How to get focus on subclassed textfield?

I have created sub class because i wants to hide the menuitem when double tapping on uitextfield. Menu item gets hide but the caret is still showing.

how to hide the caret(blue color rect that is used to select text)?

I think it's easier if you set the delegate for the UITextField and implement the method:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    textField.layer.borderColor = [UIColor colorWithWhite:0.768 alpha:1.000].CGColor;
    return YES;
}

You set the textfield color according to you.

to hide the color of cursor set this.

[[UITextField appearance] setTintColor:[UIColor redColor]];

Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM