Search code examples
swiftuisegmentedcontrol

Hide a label based on selection of UISegmented controls at run time


I have two segments in UISegmented Controls. What I want is to hide a label based upon selection of segment at run time.

For e.g:

if SegControl.selectedSegmentIndex == 1 {
    descriptStar.isHidden = true
    PriceStar.isHidden = true                               
}

I am trying this but it is not working. Please help.

Thanks


Solution

  • I previously had an outlet from segmentedControl but not an @IBAction method. I created an @IBAction method connected to the segmented control and inserted the code to hide labels in that function and it worked.