Can't add UIButton Outlet to UIView
I'm only able to add an Action to my UIView subclass and not an Outlet. But I am able to add an Outlet to the parent controller that is holding the UIView.
You cannot actually add a IBOutlet of a button to the UIView subclass, because your UIView subclass doesn't own this object. You need to assign a subclass of UIButton to make an outlet, or use parent ViewController class, that own all the subviews
You can only add
UIViewprogramatically, but there's no we to do it with an
let testView: UIView = UIView(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) let button = UIButton() self.testView.addSubview(button)