我想在按下uibutton时启用/禁用uitextfield。
当我按下enable ui按钮时,它允许我在uitextfield上键入
但当我按disable时,它会禁止我在uitextfield上键入内容。

最佳答案

只需按照以下步骤获取问题的解决方案:
1)为按钮和文本字段准备IBoutlet

@IBOutlet var btnEnable : UIButton!
@IBOutlet var btnDisable : UIButton!
@IBOutlet var txtValue : UITextField!

2.)现在,在viewDidLoad()中,将标记按钮放在行的下面
self.btnEnable.tag = 0
self.btnDisable.tag = 1

3.)现在创建事件并用故事板中的两个按钮连接此事件。(注:内部两个按钮上的接线相同)
@IBAction func btnTextfieldInteractionCalled(sender : UIButton)
{
    // "o" means called enable button and "1" means disable button
    if(sender.tag == 0)
    {
        self.txtValue.userInteractionEnabled = true
    }
    else if(sender.tag == 1)
    {
        self.txtValue.userInteractionEnabled = false
    }
}

4)现在运行并检查结果。它的工作很好。:)

关于swift - 如何启用/禁用TextField SWIFT,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37041401/

10-14 17:27
查看更多