「Swift」UISegmentedControlを切り替えるサンプル
書式
switch sender.selectedSegmentIndex
使用例
import UIKit class ViewController: UIViewController { @IBOutlet weak var label: UILabel! @IBAction func segmentedControlChanged(_ sender: UISegmentedControl) { switch sender.selectedSegmentIndex { case 0: label.text = "LabelA" case 1: label.text = "LabelB" case 2: label.text = "LabelC" default: break } } override func viewDidLoad() { super.viewDidLoad() } }