Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. override func viewDidLoad() {
  2. super.viewDidLoad()
  3. // Do any additional setup after loading the view, typically from a nib.
  4.  
  5. let rect = CGRectMake(130, 100, 0, 0)
  6. let uiSwitch = UISwitch(frame: rect)
  7. uiSwitch.setOn(true, animated: true)
  8. uiSwitch.addTarget(self, action: "switchChanged", forControlEvents: UIControlEvents.ValueChanged)
  9.  
  10. self.view.addSubview(uiSwitch)
  11. }
  12.  
  13. func switchChanged(uiSwitch: UISwitch) {
  14. var message = "Turn on the switch"
  15. if uiSwitch.on {
  16. message = "Turn off the switch"
  17. }
  18. let alert = UIAlertController(title: "Information", message: message, preferredStyle: UIAlertControllerStyle.Alert)
  19. let action = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil)
  20. alert.addAction(action)
  21. self.presentViewController(alert, animated: true, completion: nil)
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement