iOS开发——UI篇Swift篇&UISwitch/UIStepper

UISwitch/UIStepper

 

 1     override func viewDidLoad() {
 2         super.viewDidLoad()
 3         
 4         titleLabel.text = titleString
 5         
 6         
 7         // Do any additional setup after loading the view.
 8         
 9         //创建开关控件
10         var switchView:UISwitch = UISwitch(frame: CGRectMake(20, 100, 60, 40))
11         
12         //添加到视图上
13         self.view.addSubview(switchView)
14         
15         //设置开启
16         switchView.on = true
17         
18         //
19         switchView.setOn(true , animated: true)
20         
21         //添加UIControlEvents.ValueChanged事件,检测开关的切换
22         switchView.addTarget(self, action: "switchChange:", forControlEvents: UIControlEvents.ValueChanged)
23         
24         
25         
26         
27         //--------------------------
28         
29         //创建进步控件
30         var stepperView:UIStepper = UIStepper(frame: CGRectMake(200, 100, 80, 40))
31         
32         //添加到视图上
33         self.view.addSubview(stepperView)
34         
35         //设置最小值,默认是0.0
36         stepperView.minimumValue = 60
37         
38         //设置最大值,默认是100.0
39         stepperView.maximumValue = 800
40         
41         //设置当前值,默认是0.0
42         stepperView.value = 100
43         
44         //设置递增或递减的值,默认是1.0
45         stepperView.stepValue = 50
46     }
47 
48     override func didReceiveMemoryWarning() {
49         super.didReceiveMemoryWarning()
50         // Dispose of any resources that can be recreated.
51     }
52     
53 
54     /*
55     // MARK: - Navigation
56 
57     // In a storyboard-based application, you will often want to do a little preparation before navigation
58     override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
59         // Get the new view controller using segue.destinationViewController.
60         // Pass the selected object to the new view controller.
61     }
62     */
63 
64     
65     //检测开关的切换的事件
66     func switchChange(sender: AnyObject?)
67     {
68 //        var newSwitch:UISwitch = sender as UISwitch
69         
70         //2015年5月2号修改
71         var newSwitch:UISwitch = sender as! UISwitch
72         
73         println(newSwitch.on)
74     }

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。