287986
287986

Reputation: 91

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)?

Upvotes: 0

Views: 593

Answers (2)

Banker Mittal
Banker Mittal

Reputation: 1918

to hide the color of cursor set this.

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

Thanks.

Upvotes: 0

Naveen kumar
Naveen kumar

Reputation: 800

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.

Upvotes: 1

Related Questions