我的视图控制器顶部有两个按钮,以模态显示。奇怪的是,当我在模拟器中单击按钮时,这些按钮根本无法选择。当我在iPhone上使用这些按钮时,它们不会造成任何问题。
btn.addTarget(self, action: #selector(sendTapped), for: .touchUpInside)
这就是我将功能添加到按钮的方式
整个按钮代码:
let post: UIButton = {
let btn = UIButton()
btn.frame = CGRect(x: 0, y: 0, width: 60, height: 30)
btn.setTitleColor(UIColor.lightGray.adjust(by: 20), for: .normal)
btn.isEnabled = false
btn.setTitle("Post", for: .normal)
btn.titleLabel?.font = UIFont.systemFont(ofSize: 20, weight: .bold)
btn.addTarget(self, action: #selector(sendTapped), for: .touchUpInside)
return btn
}()
UIView userInteractionEnabled通过InterfaceBuilder或以编程方式在该按钮上设置为false
按钮在将userInteractionEnabled设置为false的视图下面