I need to change views using a Segmented Control. In the following example I have put two view containers in the same location:
The second container is hidden and I will show it through code every time I use the segmented control. (Although it does not show it either.)
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var container1: UIView!
@IBOutlet weak var container2: UIView!
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func showComponent(_ sender: Any) {
if (sender as AnyObject).selectedSegmentIndex == 0 {
UIView.animate(withDuration: 0.5, animations: {
self.container1.alpha = 1
self.container2.alpha = 0
})
} else {
UIView.animate(withDuration: 0.5, animations: {
self.container1.alpha = 0
self.container2.alpha = 1
})
}
}
}
Do you know of any other way to do it?
Is there any way to customize the SegmentedControl as if it were a TAB?