Как создать segmentedControl программно - Swift 5
func guruFuncCreateSegmentedControl() {
Индивидуальное обучение Swift или видеокурсы по iOS разработке
it-guru.kz/courses
let courses = ["Swift", "Python", "Delphi"]
let guruSegmentedControl = UISegmentedControl(items: courses)
guruSegmentedControl.center = view.center
guruSegmentedControl.backgroundColor = .darkGray
guruSegmentedControl.selectedSegmentIndex = 1
let titleTextAttributes1 = [NSAttributedString.Key.foregroundColor: UIColor.white]
guruSegmentedControl.setTitleTextAttributes(titleTextAttributes1, for: .normal)
let titleTextAttributes2 = [NSAttributedString.Key.foregroundColor: UIColor.orange]
guruSegmentedControl.setTitleTextAttributes(titleTextAttributes2, for: .selected)
guruSegmentedControl.addTarget(self, action: #selector(guruAction(segmentedControl:)), for: .valueChanged)
view.addSubview(guruSegmentedControl)
}
@objc func guruAction(segmentedControl: UISegmentedControl) {
switch segmentedControl.selectedSegmentIndex {
case 0:
print("Welcome to the course Swift")
case 1:
print("Welcome to the course Python")
case 2:
print("Welcome to the course Delphi")
default:
break
}
}
Возврат к списку