Learn-iOS-Swift-by-Examples/UICatalog/Swift/UIKitCatalog/SwitchViewController.swift

49 lines
1.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
Abstract:
A view controller that demonstrates how to use UISwitch.
*/
import UIKit
class SwitchViewController: UITableViewController {
// MARK: - Properties
@IBOutlet weak var defaultSwitch: UISwitch!
@IBOutlet weak var tintedSwitch: UISwitch!
// MARK: - View Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
configureDefaultSwitch()
configureTintedSwitch()
}
// MARK: - Configuration
func configureDefaultSwitch() {
defaultSwitch.setOn(true, animated: false)
defaultSwitch.addTarget(self, action: #selector(SwitchViewController.switchValueDidChange(_:)), forControlEvents: .ValueChanged)
}
func configureTintedSwitch() {
tintedSwitch.tintColor = UIColor.applicationBlueColor
tintedSwitch.onTintColor = UIColor.applicationGreenColor
tintedSwitch.thumbTintColor = UIColor.applicationPurpleColor
tintedSwitch.addTarget(self, action: #selector(SwitchViewController.switchValueDidChange(_:)), forControlEvents: .ValueChanged)
}
// MARK: - Actions
func switchValueDidChange(aSwitch: UISwitch) {
NSLog("A switch changed its value: \(aSwitch).")
}
}