初学Swift之UI控件------UIButton

/**
      创建button
    */
    func createButton(){
        btnTest = UIButton()
        btnTest.frame = CGRect(x: 50, y: 150, width:screenWidth-100, height: 50)
        btnTest.backgroundColor=#colorLiteral(red: 0.4666666687, green: 0.7647058964, blue: 0.2666666806, alpha: 1)
        btnTest.titleLabel?.font = UIFont.systemFont(ofSize: 30)
        btnTest.layer.shadowColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
        btnTest.layer.shadowOffset = CGSize(width: 2, height: 2)
        
        btnTest.layer.masksToBounds = true
        btnTest.layer.borderColor = #colorLiteral(red: 0.9764705896, green: 0.850980401, blue: 0.5490196347, alpha: 1)
        btnTest.layer.cornerRadius = 23
        btnTest.layer.borderWidth = 2
        
        btnTest.setTitle("暂停", for: .normal)
        btnTest.setTitleColor(UIColor.black, for: .normal)
        btnTest.setTitleShadowColor(UIColor.red, for: .normal)
        
        btnTest.setTitle("触摸状态", for: .highlighted)
        btnTest.setTitleColor(UIColor.red, for: .highlighted)
        btnTest.setTitleShadowColor(UIColor.green, for: .highlighted)
        
        btnTest.setTitle("禁用状态", for: .disabled)
        btnTest.setTitleColor(UIColor.gray, for: .disabled)
        btnTest.setTitleShadowColor(UIColor.black, for: .disabled)
        self.view.addSubview(btnTest)
        
        btnTest.addTarget(self, action: #selector(myClick(sender:)), for: .touchUpInside)
    }
    
    @objc func myClick(sender:UIButton){
        print("触发了点击事件")
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值