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

后端 未结 4 1507
夕颜
夕颜 2021-02-01 15:52

So I\'ve created a ViewControl in my storyboard that has 3 subviews. Each one represents a different view I want to show depending on which table row was selected on the previou

相关标签:
4条回答
  • 2021-02-01 16:09

    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
    
    0 讨论(0)
  • 2021-02-01 16:10

    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

    0 讨论(0)
  • 2021-02-01 16:24

    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.

    0 讨论(0)
  • 2021-02-01 16:34

    Use this to hide a view in swift

    viewVar.isHidden = true
    
    0 讨论(0)
提交回复
热议问题