Контроль 3 сегментированный
Использую Xcode 8.1, swift 3.0
у меня есть код сегментировал свою работу с 2-мя элементами управления
когда я пытаюсь добавить 3, не работает ни одной идеи, что не так с моим кодом
эта работа с 2-х сегментированных
@IBAction func showComponent(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
UIView.animate(withDuration: 0.0, animations: {
self.containerViewA.alpha = 1
self.containerViewB.alpha = 0
})
} else {
UIView.animate(withDuration: 0.0, animations: {
self.containerViewA.alpha = 0
self.containerViewB.alpha = 1
})
}
}
этот не работает с 3 сегментированных
здесь пробую новый код с 3x сегментированным управлением;
@IBAction func showComponent(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
UIView.animate(withDuration: 0.5, animations: {
self.containerViewA.alpha = 1
self.containerViewB.alpha = 0
self.containerViewC.alpha = 0
})
UIView.animate(withDuration: 0.5, animations: {
self.containerViewA.alpha = 0
self.containerViewB.alpha = 1
self.containerViewC.alpha = 0
} else {
UIView.animate(withDuration: 0.5, animations: {
self.containerViewA.alpha = 0
self.containerViewB.alpha = 0
self.containerViewC.alpha = 1
})
}
}
1 ответ
Решение
Хорошо я пытался с этим кодом его работу сейчас:)
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var orange: UIView!
@IBOutlet weak var yellow: UIView!
@IBOutlet weak var red: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func showComponent(_ sender: UISegmentedControl) {
if sender.selectedSegmentIndex == 0 {
self.orange.alpha = 1
self.yellow.alpha = 0
self.red.alpha = 0
}
if sender.selectedSegmentIndex == 1 {
self.orange.alpha = 0
self.yellow.alpha = 1
self.red.alpha = 0
}
if sender.selectedSegmentIndex == 2 {
self.orange.alpha = 0
self.yellow.alpha = 0
self.red.alpha = 1
}
}
}