码迷,mamicode.com
首页 > 其他好文 > 详细

080滑动滑块时显示对应的值

时间:2015-06-15 21:46:30      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:

效果如下:

技术分享

ViewController.h

1 #import <UIKit/UIKit.h>
2 
3 @interface ViewController : UIViewController
4 @end

ViewController.m

 1 #import "ViewController.h"
 2 
 3 @interface ViewController ()
 4 
 5 - (void)layoutUI;
 6 - (void)sliderDidChange:(UISlider *)sender;
 7 @end
 8 
 9 @implementation ViewController
10 
11 - (void)viewDidLoad {
12     [super viewDidLoad];
13     
14     [self layoutUI];
15 }
16 
17 - (void)didReceiveMemoryWarning {
18     [super didReceiveMemoryWarning];
19     // Dispose of any resources that can be recreated.
20 }
21 
22 - (void)layoutUI {
23     CGFloat currentColorVal = 0.5;
24     self.view.backgroundColor = [UIColor colorWithRed:currentColorVal green:currentColorVal blue:currentColorVal alpha:1.0];
25     
26     UISlider *sldBackgroundColor = [[UISlider alloc] initWithFrame:CGRectMake(0, 0, 250, 50)];
27     sldBackgroundColor.center = self.view.center;
28     sldBackgroundColor.minimumValue = 0.0; //左端点
29     sldBackgroundColor.maximumValue = 1.0; //右端点
30     sldBackgroundColor.value = currentColorVal;
31     [sldBackgroundColor addTarget:self
32                action:@selector(sliderDidChange:)
33      forControlEvents:UIControlEventValueChanged];
34     [self.view addSubview:sldBackgroundColor];
35 }
36 
37 - (void)sliderDidChange:(UISlider *)sender {
38     CGFloat currentColorVal = sender.value;
39     NSLog(@"currentColorVal=%0.2f", currentColorVal); //currentColorVal=0.50
40     self.view.backgroundColor = [UIColor colorWithRed:currentColorVal green:currentColorVal blue:currentColorVal alpha:1.0];
41 }
42 
43 @end

 

080滑动滑块时显示对应的值

标签:

原文地址:http://www.cnblogs.com/huangjianwu/p/4579176.html

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