How to create custom view programmatically in swift having controls text field, button etc

前端 未结 5 1868
星月不相逢
星月不相逢 2020-12-08 12:51

I am trying to access the MyCustomView from another class using the following code in ViewController.swift ..

var view = MyCustomView(frame: CGR         


        
5条回答
  •  佛祖请我去吃肉
    2020-12-08 13:38

    var customView = UIView()
    
    
    @IBAction func drawView(_ sender: AnyObject) {
    
        customView.frame = CGRect.init(x: 0, y: 0, width: 100, height: 200)
        customView.backgroundColor = UIColor.black     //give color to the view 
        customView.center = self.view.center  
        self.view.addSubview(customView)
           }
    

提交回复
热议问题