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

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.


Use this to hide a view in swift

viewVar.isHidden = true

however the fact that isHidden is a naming convention for checking the status and is a getter method but despite that fact in swift we use it as setter and getter property

view.isHidden = true

Tags:

Ios

Uiview

Swift