按钮
btn = UIButton()
btn.rx.controlEvent(.touchUpInside).subscribe { (btn) in
print("按钮点击")
}.disposed(by: bag)
btn.backgroundColor = .red
view.addSubview(btn)
btn.snp.makeConstraints { (make) in
make.top.left.equalTo(50)
make.height.equalTo(100)
make.right.equalTo(-50)
}
控件手势的使用
lab = UILabel()
view.addSubview(lab)
lab.textColor = .white
lab.backgroundColor = .blue
lab.snp.makeConstraints { (make) in
make.top.equalTo(btn.snp.bottom).offset(10)
make.left.equalTo(10)
make.height.equalTo(30)
make.right.equalTo(-10)
}
let tap = UITapGestureRecognizer()
lab.isUserInteractionEnabled = true
lab.addGestureRecognizer(tap)
lab.tag = 99
tap.rx.event.bind { (tap) in
print(tap.location(in: self.view),tap.view?.tag)
}.disposed(by: bag)
网友评论