I\'m trying to avoid an app crash here... I have a button that will remove a segment from a UISegmentedControl. If that button is pressed and the user has the segment to be
This code is for swift 2.0
@IBOutlet weak var segmentcontroll: UISegmentedControl!
@IBAction func segmentneeded(sender: AnyObject)
{
if(segmentcontroll.selectedSegmentIndex==0)
{
self.view.backgroundColor=UIColor.purpleColor()
segmentcontroll.selectedSegmentIndex=UISegmentedControlNoSegment
}
else if(segmentcontroll.selectedSegmentIndex==1)
{
self.view.backgroundColor=UIColor.yellowColor()
segmentcontroll.selectedSegmentIndex=UISegmentedControlNoSegment
}
else
{
self.view.backgroundColor=UIColor.grayColor()
segmentcontroll.selectedSegmentIndex=UISegmentedControlNoSegment
}
}
Use like this.. yourSegmentname.selectedSegmentIndex = 1;
// or whichever segment you want