-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUISwitchVC.swift
38 lines (30 loc) · 1.04 KB
/
UISwitchVC.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//
// UISwitchVC.swift
// UIKitDemo
//
// Created by Kyrie Miyajima on 2015/02/13.
// Copyright (c) 2015年 Kirie Miyajima. All rights reserved.
//
import UIKit
class UISwitchViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad();
self.title = "UISwitch";
self.view.backgroundColor = UIColor.whiteColor();
let mySwitch:UISwitch = UISwitch();
mySwitch.layer.position = CGPoint(x: self.view.frame.width/2, y: self.view.frame.height/2);
mySwitch.on = false;
mySwitch.addTarget(self, action: #selector(self.switchOn(_:)), forControlEvents: UIControlEvents.ValueChanged);
self.view.addSubview(mySwitch);
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning();
}
func switchOn(sender: UISwitch){
if sender.on == true{
self.view.backgroundColor = UIColor.greenColor();
}else{
self.view.backgroundColor = UIColor.whiteColor();
}
}
}