UITextfield 中的编辑模式问题

Editing mode issue in UITextfield

我在文本字段中使用 uipickerview。当我单击任何文本字段时,将显示一个 uipickerview,我们可以 select 来自 uipickerview 的任何值。

所以,我的问题是。当我点击文本字段时,uipicker 将会出现,并且会显示文本字段编辑模式。

因此,当我单击“帮助主题”文本字段时,选择器出现了,并且在文本字段中显示了编辑模式。 怎么解决。我的意思是,我不想要那种编辑选项模式。 当我单击文本字段时,只会显示选择器,这就是我想要的。 怎么做 ?

只写一行

Swift

yourTextFieldObject.tintColor = .clear // "yourTextFieldObject" is "HelpTopics" textField's object

Objective-C

yourTextFieldObject.tintColor = [UIColor clearColor]; // "yourTextFieldObject" is "HelpTopics" textField's object

但是上面的代码你的 textField 光标颜色会很清晰,不会显示。

Swift 3+: 使用这个 UITextFieldDelegate 方法。只需写下这些行。

func textFieldDidBeginEditing(_ textField: UITextField) {
            if textField == yourTextField{
                textField.resignFirstResponder()
             // Open your picker here.
            }
        }