Hide the cursor of an UITextField

后端 未结 13 853
甜味超标
甜味超标 2020-12-07 07:51

I am using a UITextField with a UIPickerView for its inputView, so that when the user taps the text field, a picker is summoned for th

13条回答
  •  不知归路
    2020-12-07 08:44

    Answer provided by the OP, copied from the question body to help clean up the ever growing tail of unanswered questions.

    I think I have the correct solution but If it can be improved will be welcome :) Well, I made a subclass of UITextField and overriden the method that returns the CGRect for the bounds

    -(CGRect)textRectForBounds:(CGRect)bounds {
        return CGRectZero;
    }
    

    The problem? The text doesn't show because the rect is zero. But I added an UILabel as a subview of the control and overridden the setText method so, as we enter a text as usual, the text field text is nil and is the label which shows the text

    - (void)setText:(NSString *)aText {
        [super setText:nil];
    
        if (aText == nil) {
            textLabel_.text = nil;
        }
    
        if (![aText isEqualToString:@""]) {
            textLabel_.text = aText;
        }
    }
    

    With this the thing works as expected. Have you know any way to improve it?

提交回复
热议问题