UIButton(按钮)

  lazy var deleBtn: UIButton = {
        
        let button = UIButton ()
        button.setTitle("删除", for: .normal)
        button.setTitleColor(UIColor.white, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        button.backgroundColor = UIColor.red
        button.layer.borderColor = UIColor.black.cgColor
        button.layer.borderWidth = 0.5
        button.layer.cornerRadius = 3
        button.layer.masksToBounds = true
        button.addTarget(self, action: #selector(onRightBtnClicked), for: .touchUpInside)
        
        return button
    }()

    @objc func onRightBtnClicked(_ sender:UIButton){
    }

deleBtn.snp.makeConstraints { (make) -> Void in
            make.left.right.equalTo(self.view)
            make.height.equalTo(50)
            make.width.equalTo(50)
        }

拓展

#@-------图片上下左右
btnCenter.set(image: UIImage(named: "意见反馈"), title: "支付宝", titlePosition: .bottom,
                   additionalSpacing: 10.0, state: .normal)
#@-------按钮验证码计时器
btnCode.mj_countDown(count: 10, enabledColor: UIColor.MJTheme.gray)

图片按钮

lazy var Btn: UIButton = {
        
        let button = UIButton ()
        button.setImage(UIImage.init(named: "tab_service"), for: .normal)
        button.imageView?.contentMode = .scaleAspectFit
        button.setTitle("分享", for: .normal)
        button.addTarget(self, action: #selector(clickBtn), for: .touchUpInside)

        return button
    }()
//按钮按下后的模糊状态
 button.adjustsImageWhenHighlighted = false  //使触摸模式下按钮也不会变暗(半透明)
 button.adjustsImageWhenDisabled=false //使禁用模式下按钮也不会变暗(半透明)

##禁用点击事件,一起用
self.btnSelect.enabled = NO;
self.btnSelect.adjustsImageWhenDisabled = NO;

UIButton 用法
http://www.hangge.com/blog/cache/detail_529.html
https://www.jianshu.com/p/c69c72570285
扩展UIButton
http://www.hangge.com/blog/cache/detail_960.html
https://www.jianshu.com/p/4676d84458f7
自定义UIButton
https://www.jianshu.com/p/f76b68440758

##图片文字按钮 1

你可能感兴趣的:(UIButton(按钮))