Disabling user input for UITextfield in swift

后端 未结 8 1001
半阙折子戏
半阙折子戏 2021-02-01 11:55

pretty trivial question, I know. But I can not find anything online.

I need to disable the user from being able to edit the text inside of a text field. So that when the

8条回答
  •  你的背包
    2021-02-01 12:32

    In storyboard you have two choise:

    1. set the control's 'enable' to false.

    enter image description here

    1. set the view's 'user interaction enable' false

    enter image description here

    The diffierence between these choise is:

    the appearance of UITextfild to display in the screen.

    enter image description here

    1. First is set the control's enable. You can see the backgroud color is changed.
    2. Second is set the view's 'User interaction enable'. The backgroud color is NOT changed.

    Within code:

    1. textfield.enable = false
    2. textfield.userInteractionEnabled = NO

      Updated for Swift 3

      1. textField.isEnabled = false
      2. textfield.isUserInteractionEnabled = false

提交回复
热议问题