【发布时间】:2017-06-06 21:36:23
【问题描述】:
请检查以下代码。 我在 mainView 上制作了按钮。 但按钮不调用“thumbsUpButtonPressed”方法。 请检查!
override func viewDidLoad() {
super.viewDidLoad()
let button = UIButton(type: .custom)
button.frame = CGRect(x: 60, y: 100, width: 50, height: 50)
button.backgroundColor = .red //.clear
button.layer.cornerRadius = 5
button.layer.borderWidth = 1
button.layer.borderColor = UIColor.black.cgColor
button.clipsToBounds = true
//button.setImage(UIImage(named:"thumbsUp.png"), for: .normal)
button.addTarget(self, action: #selector(thumbsUpButtonPressed), for: .touchDown)
view.addSubview(button)
}
func thumbsUpButtonPressed(sender: UIButton) {
print("thumbs up button pressed")
}
【问题讨论】:
-
我试过你的代码,它打印出“按下了竖起大拇指的按钮”,我看不出有什么问题。你还有更多代码要展示吗?
-
谢谢。但仅此而已。我制作了 5 个 TabView,它是第一个 TabView 上的代码。你认为这段代码在 TabView 上不起作用吗?
标签: ios swift button swift3 touch