gpt4 book ai didi

ios - 快速点击 UIButton 没有响应

转载 作者:行者123 更新时间:2023-11-30 12:22:51 25 4
gpt4 key购买 nike

    addButton = UIButton(type: .custom)
addButton.setTitle("add", for: .normal)
addButton.setTitle("tapped", for: .highlighted)
addButton.titleLabel?.font = UIFont.systemFont(ofSize: 12)
addButton.backgroundColor = UIColor.lightGray
addButton.translatesAutoresizingMaskIntoConstraints = false
addButton.addTarget(self, action: #selector(dosome(_:)), for: .touchUpInside)
let bottom_button: NSLayoutConstraint = NSLayoutConstraint(item: addButton, attribute: NSLayoutAttribute.bottom, relatedBy:NSLayoutRelation.equal, toItem:mainView, attribute:NSLayoutAttribute.bottom, multiplier:1.0, constant: -10)
let right_button: NSLayoutConstraint = NSLayoutConstraint(item: addButton, attribute: NSLayoutAttribute.right, relatedBy:NSLayoutRelation.equal, toItem:mainView, attribute:NSLayoutAttribute.right, multiplier:1.0, constant: -20)
let height_button: NSLayoutConstraint = NSLayoutConstraint(item: addButton, attribute: NSLayoutAttribute.height, relatedBy:NSLayoutRelation.equal, toItem:nil, attribute:.notAnAttribute, multiplier:1.0, constant: 20)
let width_button: NSLayoutConstraint = NSLayoutConstraint(item: addButton, attribute: NSLayoutAttribute.width, relatedBy:NSLayoutRelation.equal, toItem:nil, attribute:.notAnAttribute, multiplier:1.0, constant: 35)
addButton.addConstraint(height_button)
addButton.addConstraint(width_button)
mainView.addSubview(addButton)
mainView.addConstraint(bottom_button)
mainView.addConstraint(right_button)

@IBAction func dosome(_ sender: UIButton) {
print("tttttt")
}

点击后,按钮的文本将变为突出显示的标题,而无需执行任何操作。谁能指出哪里出了问题吗?

最佳答案

使用addButton.isHighlighted = false它会起作用。

关于ios - 快速点击 UIButton 没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44583681/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com