美文网首页
Swift UIButton 属性

Swift UIButton 属性

作者: Albert新荣 | 来源:发表于2019-05-28 18:31 被阅读0次
       btn  = UIButton(type:.custom)
        btn.setTitle("点击开始", for: .normal)
        btn.setTitleColor(UIColor.red, for: .normal)
        btn.addTarget(self, action: #selector(buttonClick(btn:)), for: .touchUpInside)
        //字体
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        //设置圆角
        btn.layer.masksToBounds = true
        btn.layer.cornerRadius = 5.0
        //设置边框
        btn.layer.borderColor = UIColor.purple.cgColor
        btn.layer.borderWidth = 1.5
        self.view.addSubview(btn)
        btn.snp.makeConstraints { (make) in
            make.center.equalTo(self.view)
            make.size.equalTo(CGSize(width: 100, height: 100))
        }
let button1 = UIButton(frame:CGRect(x:ScreenWidth/2-60, y:ScreenHeight/2, width:120, height:120))
self.view.addSubview(button1)
button1.setTitle("图片按钮", for: .normal)
button1.setImage(UIImage(named:"hightImage.png"), for: .normal)
button1.backgroundColor = UIColor.red
// 上左下右 根据自己图片和文字布局自行调整参数设置
button1.imageEdgeInsets = UIEdgeInsetsMake(0, 25, 50, 0)
button1.titleEdgeInsets = UIEdgeInsetsMake(0, -25, -50, 10)

相关文章

网友评论

      本文标题:Swift UIButton 属性

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