Swift 4.0 按钮

 //按钮位置
        let button:UIButton=UIButton(frame:CGRect(x: self.view.frame.width/2-60, y: 64+60, width: 120, height: 120))
        //按钮背景颜色
        button.backgroundColor=UIColor.red
        //按钮设置圆角
        button.layer.masksToBounds=true
        button.layer.cornerRadius=13
        //按钮插入背景图片
        button.setBackgroundImage(UIImage(named: "2.jpg"), for: UIControl.State.normal)
        //按钮点击方法
        button.addTarget(self, action: #selector(click), for: .touchUpInside)

按钮的点击放生时间

    @objc func click(){
//        let tag = sender.tag
        print("哈哈哈")
        
    }

猜你喜欢

转载自blog.csdn.net/qq_43361450/article/details/84952866