我想在按下 ui 按钮时启用/禁用 UITextField。
当我按下启用 ui 按钮时,它使我能够在 uitextfield 上键入 但是当我按下禁用时,它会禁用我在 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.) 现在创建事件并使用 Storyboard 中的两个按钮连接此事件。 (注意:同一事件连接在两个按钮 Touch Up Inside 上)
@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/