码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2015-06-07 23:20:28      阅读:318      评论:0      收藏:0      [点我收藏+]

标签:

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     }

 

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

标签:

原文地址:http://www.cnblogs.com/iCocos/p/4559170.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!