A custom animated segmented control
Download the SegmentedControl.swift file and add it into your own project
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
setupSegmentedControl()
}
func setupSegmentedControl() {
let segmentedControl = SegmentedControl(frame: CGRect(x:0, y:0, width: 200, height: 45), tabIcons: [UIImage(named: "beer_icon"), UIImage(named: "bar_icon"), UIImage(named: "night_club"), UIImage(named: "restaurant")], controlColor: UIColor.orange, selectedTabColor: UIColor.white, tabTintColor: UIColor.white)
segmentedControl.delegate = self
view.addSubview(segmentedControl)
}
}
extension ViewController: SegmentedControlDelegate {
func tabSelected(atIndex index: Int) {
print("Selected tab at index \(index)")
}
}