最新消息:20210917 已从crifan.com换到crifan.org

[已解决]swift中UITextFiled设置为只读不允许修改内容

iOS crifan 5483浏览 0评论

想要去设置一个UITextFiled为只读,不允许用户点击后出现键盘

不允许用户修改内容

发现没有readonly选项

也没有editable为false的选项

swift uitextfield not editable

UITextField copyable but not editable Swift – Stack Overflow

不想要改为UITextView

ios – Changing UITextfield from Non-Editable to Editable – Swift – Stack Overflow

去设置:userInteractionEnabled为false试试

ios – Disabling user input for UITextfield in swift – Stack Overflow

用:

textFieldShouldBeginEditing

不太好,太麻烦了。

对了,可以设置:

enabled = false

好像也是可以起到类似的效果的。

        if editable {

            self.rightTextfield.userInteractionEnabled = true

            self.rightTextfield.enabled = false

        } else {

            self.rightTextfield.userInteractionEnabled = false

            self.rightTextfield.enabled = false

        }

然后的确起到效果了:

默认可以编辑:

设置:

self.rightTextfield.userInteractionEnabled = false

或:

self.rightTextfield.enabled = false

都可以达到,点击后,无法弹出键盘,无法编辑的状态。

转载请注明:在路上 » [已解决]swift中UITextFiled设置为只读不允许修改内容

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
100 queries in 0.211 seconds, using 23.38MB memory