Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - possible to not show keyboard but still show the cursor in a UITextField?

I have a custom keyboard I want to show when the user taps a UITextField. But at the same time I want to show the cursor in the textfield. If if return a NO for canBecomeFirstResponder, it doesn't show the default keyboard but doesn't show the cursor either.

Can someone please help me out?

Thanks.

like image 281
Swastik Avatar asked Apr 04 '10 07:04

Swastik


2 Answers

The answer to your problem is to create a view for your custom keyboard and then edit the inputView property of your UITextField and pass it the view for your custom keyboard.

I hope that helps.

like image 189
arturovm Avatar answered Sep 30 '22 18:09

arturovm


override following two methods in UITextFieldDelegate. Note that this approach is valid for both UITextField and UITextView (in which case you override corresponding methods in UITextViewDelegate)

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    if (!textField.inputView) {
        //hides the keyboard, but still shows the cursor to allow user to view entire text, even if it exceeds the bounds of the textfield
        textField.inputView = [[UIView alloc] initWithFrame:CGRectZero];
    }
    return YES;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    return NO;
}
like image 39
Yogi Avatar answered Sep 30 '22 17:09

Yogi