美文网首页
RXSwift使用

RXSwift使用

作者: Ciao丶 | 来源:发表于2021-08-26 13:28 被阅读0次

    按钮

        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)

    相关文章

      网友评论

          本文标题:RXSwift使用

          本文链接:https://www.haomeiwen.com/subject/fzfuiltx.html