rga*_*ber 8 xcode uipickerview uitextfield ios swift
我有一个UITextField我正在使用UIPickerView的inputView.用户可以从选择器中选择一个值,并将选定的值填充到我的TextInput.
这种安排工作正常,但有以下问题:
1)我想禁用仍然显示在中的光标UITextField.
我试过禁用它UITextField,但它没有响应触摸,然后UIPickerView没有显示 - 这使它无用.
2)由于显示了选择器并且键盘没有用户点击文本字段,用户无法键入任何内容,但仍可以通过长按来粘贴从其他地方复制的文本.我怎么能禁用它?
我无法在线查找相关信息.我应该使用a Label还是Buttonfor for而不是UITextInput?
就像TonyMkenu所说,你需要继承UITextField,然后实现他上面的方法.对于那些不了解Objective C的人来说,这是Swift:
override func caretRectForPosition(position: UITextPosition!) -> CGRect {
return CGRect.zeroRect
}
override func selectionRectsForRange(range: UITextRange) -> [AnyObject] {
return []
}
override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
// Disable copy, select all, paste
if action == Selector("copy:") || action == Selector("selectAll:") || action == Selector("paste:") {
return false
}
// Default
return super.canPerformAction(action, withSender: sender)
}
Run Code Online (Sandbox Code Playgroud)
我认为简单的方法是用按钮代替它 UITextField
对不起 - 这不是为了Swift它,Obj-C但这是个主意:
要做你想要的事情UITextField你必须继承UITextField并尝试使用此代码来禁用/隐藏插入符号和输入(复制/粘贴)
- (CGRect) caretRectForPosition:(UITextPosition*) position
{
return CGRectZero;
}
- (NSArray *)selectionRectsForRange:(UITextRange *)range
{
return nil;
}
- (BOOL)canPerformAction:(SEL)action withSender:(id)sender
{
if (action == @selector(copy:) || action == @selector(selectAll:) || action == @selector(paste:))
{
returnNO;
}
return [super canPerformAction:action withSender:sender];
}
Run Code Online (Sandbox Code Playgroud)
示例来自:http://b2cloud.com.au/tutorial/disabling-the-caret-and-text-entry-in-uitextfields/
无论如何......这是一个"功能"的例子:https://github.com/hackiftekhar/IQDropDownTextField
| 归档时间: |
|
| 查看次数: |
8454 次 |
| 最近记录: |