UIButton(按钮)

2017-05-11  本文已影响19人  Alan龙马
  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(clickBtn1), for: .touchUpInside)
        
        return button
    }()
    
    @objc func clickBtn1(_ sender:UIButton)
    {
    }

图片按钮

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

##图片文字按钮
上一篇 下一篇

猜你喜欢

热点阅读