Jos*_*eld 16 objective-c uitextfield ios inputview
如何在UITextField隐藏光标/插入符号/放大镜的同时防止编辑文本,但仍然显示键盘,因为我使用的inputView是UIPickerView/ UIDatePickerView?
设置userInteractionEnabled为NO不起作用,因为它不再接收任何触摸并且不会显示键盘.
Jos*_*eld 17
子类UITextField
//Disables caret
- (CGRect)caretRectForPosition:(UITextPosition *)position
{
return CGRectZero;
}
//Disables magnifying glass
-(void)addGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
{
if ([gestureRecognizer isKindOfClass:[UILongPressGestureRecognizer class]])
{
gestureRecognizer.enabled = NO;
}
[super addGestureRecognizer:gestureRecognizer];
}
Run Code Online (Sandbox Code Playgroud)
在你的UITextFieldDelegate中
//Prevent text from being copied and pasted or edited with bluetooth keyboard.
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
return NO;
}
Run Code Online (Sandbox Code Playgroud)
现在只需从UIPickerView/UIDatePicker的结果中以编程方式设置文本.
Chr*_*ner 15
在iOS 7中隐藏光标要简单得多.仍然需要一些技巧来禁用放大镜
textField.tintColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)
我希望这对你有所帮助.
设置光标UIColor - > Empty.在UI中,它将被隐藏.
[[self.textField valueForKey:@"textInputTraits"] setValue:[UIColor clearColor] forKey:@"insertionPointColor"];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9062 次 |
| 最近记录: |