Tob*_*olz 28 cursor uidatepicker uitextfield
我按照这里的说明成功设置了一个UITextField,它使用UIDatePicker进行更新.但是UITextField中的光标闪烁,这对我来说似乎有点尴尬.是否有任何解决方案摆脱光标?
Jam*_*man 45
我意识到这是一个老问题,但随着iOS 7的更新,现在可以通过执行以下操作来隐藏光标:
[[self textFieldName] setTintColor:[UIColor clearColor]];
它只适用于iOS 7+.
Pra*_*ypa 39
子类UITextfield并覆盖- (CGRect)caretRectForPosition:(UITextPosition *)position方法并返回CGRectZero.
- (CGRect)caretRectForPosition:(UITextPosition *)position {
return CGRectZero;
}
Run Code Online (Sandbox Code Playgroud)
Bal*_*i G 32
我希望它对你有所帮助.
设置光标UIColor - >清空.
[[self.textField valueForKey:@"textInputTraits"] setValue:[UIColor clearColor] forKey:@"insertionPointColor"];
Run Code Online (Sandbox Code Playgroud)
在Swift中:2.3
self.textField.valueForKey("textInputTraits")?.setValue(UIColor.clearColor() , forKey:"insertionPointColor")
Run Code Online (Sandbox Code Playgroud)
我无法获得jcm的解决方案.我最终做的是将UILabel子类化为模仿UITextField的交互功能而没有我不想要的部分(如光标).我在这里写了一篇关于它的博客文章:
http://pietrorea.com/2012/07/how-to-hide-the-cursor-in-a-uitextfield/
基本上,UILabel子类需要覆盖isUserInteractionEnabled,inputView,inputViewAccessory和canBecomeFirstResponder.这只是几行代码而且更有意义.
我所做的是将另一个 UITextField 覆盖在我想要隐藏光标的 UITextField 之上。然后在委托方法 textFieldShouldBeginEditing 中,我将另一个 textField 设置为第一响应者并返回 NO。
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
if (textField.tag==TAG_OF_DUMMY_TEXTFIELD) {
[otherField becomeFirstResponder];
return NO;
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
然后在日期选择器调用的方法中:
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@YOUR_DATE_FORMAT];
dummyField.text = [dateFormatter stringFromDate:datePicker.date];
Run Code Online (Sandbox Code Playgroud)
在 Interface Builder 中,otherField(带有 datePicker 输入视图的字段)位于 dummyField(隐藏光标的字段)后面。
| 归档时间: |
|
| 查看次数: |
23873 次 |
| 最近记录: |