func aa(){
        let btn:UIButton = UIButton.init(type: UIButton.ButtonType.custom);//新建btn
        btn.frame = CGRect.init(x: 10, y: 10, width: 100, height: 100);//frame位置和大小
        btn.backgroundColor = UIColor.red;//背景色
        btn.imageView?.image = UIImage.init(named: "aaa")//设置图片
        btn.layer.cornerRadius = 10
        btn.layer.masksToBounds = true //设置圆角
        btn.setTitle("点击", for:  UIControl.State.normal)//设置标题
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 17)//设置字体大小
        self.view.addSubview(btn);
        //没有有参数
//        btn.addTarget(self, action: #selector(btnClick), for: UIControl.Event.touchUpInside);
        btn.addTarget(self, action:#selector(tapped(_:)), for:UIControl.Event.touchUpInside)
        
        
    }
//没有参数
//    @objc func btnClick(){
//        print("----------")
//    }
    @objc func tapped(_ btn:UIButton){
        print("----------")
    }

 

相关文章:

  • 2022-12-23
  • 2021-12-26
  • 2021-08-06
  • 2021-09-22
  • 2021-06-24
  • 2021-06-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案