swift 懒加载按钮

     // 懒加载按钮w
        lazy var btn:UIButton = {
            let btn = UIButton(frame: CGRect(x:150,y: 200, width:  50, height:50))
            btn.backgroundColor = UIColor.red
            btn.setTitle("跳转",for: UIControlState.normal)
            //btn.addTarget(self, action:#selector(tapped(:)), for:.touchUpInside)
            btn.addTarget(self, action: #selector(tapped), for: UIControlEvents.touchUpInside)
           // btn.addTarget(self, action: #selector(tapped(:)), for: .touchUpInside)
            return btn
        }()

你可能感兴趣的:(swift 懒加载按钮)