How do I show and/or hide a subview using swift How do I show and/or hide a subview using swift ios ios

How do I show and/or hide a subview using swift


Use this to hide a view in swift

viewVar.isHidden = true


You should create IBOutlets for each of the three subviews. Then you can show/hide each of them directly from those references. If you hide a view, it will automatically hide its subviews.

Once you have an outlet for the view, you can do this:

viewYouWantToHide.isHidden = true


If you have tags for each view you can hide and display them using:

Objective C

For Hiding:

[[self.view viewWithTag:1] setHidden:YES];

Showing:

[[self.view viewWithTag:1] setHidden:NO];

In Swift:

Hiding:

self.view.viewWithTag(1)?.isHidden = true

Showing:

self.view.viewWithTag(1)?.isHidden = false

NOTE: Replace 1 with your tag value.