Swift addsubview and remove it

前端 未结 5 1291
一向
一向 2020-12-13 03:15

I want to add sub view and remove with one tap. This is my code:

/* To add subview */

var testView: UIView = UIView(frame: CGRectMake(0, 0, 320, 56         


        
5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-13 04:09

    Tested this code using XCode 8 and Swift 3

    To Add Custom View to SuperView use:

    self.view.addSubview(myView)

    To Remove Custom View from Superview use:

    self.view.willRemoveSubview(myView)

提交回复
热议问题