小编Rus*_*kar的帖子

子视图按钮不起​​作用

masterBtn.addTarget(self, action: #selector(self.masterBed), for: UIControlEvents.touchUpInside)
Run Code Online (Sandbox Code Playgroud)

我在子视图中使用了上面的代码,但它没有触发功能masterBed。子视图中的按钮不可点击

完整代码:

let button = UIButton(frame: CGRect(x: 100, y: 100, width: 100, height: 50))
button.setTitleColor(.gray, for: .normal)
button.center = CGPoint(x: 380, y: 110)
button.setTitle(">", for: .normal)
button.addTarget(self, action: #selector(buttonAction), for: .touchUpInside)
self.addSubview(button)

func buttonAction () {
    print("button pressed")
}
Run Code Online (Sandbox Code Playgroud)

uibutton ios uicontrolevents swift

0
推荐指数
1
解决办法
7956
查看次数

标签 统计

ios ×1

swift ×1

uibutton ×1

uicontrolevents ×1