Hide the cursor of an UITextField

后端 未结 13 825
甜味超标
甜味超标 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:27

    I simply subclass UITextField, and override layoutSubviews as follows:

    - (void)layoutSubviews
    {
        [super layoutSubviews];
        for (UIView *v in self.subviews)
        {
            if ([[[v class] description] rangeOfString:@"UITextSelectionView"].location != NSNotFound)
            {
                v.hidden = YES;
            }
        }
    }
    

    It's a dirty hack, and may fail in the future (at which point the cursor will be visible again - your app won't crash), but it works.

提交回复
热议问题