LG_CodeMachine的博客

混迹北京 撸码谋粥

iOS控件之UISlider

滑动控件UISlider视图

一,作用:控制系统声音,或者表示播放进度等等

二,常用属性
// 设置获取slider的value值
@property(nonatomic) float value;


// 设置slider的最小值
@property(nonatomic) float minimumValue;


// 设置slider的最大值
@property(nonatomic) float maximumValue;


// 设置图片
@property(nonatomic,retain) UIImage *minimumValueImage;


// 设置图片
@property(nonatomic,retain) UIImage *maximumValueImage;


// 设置slider的value值,是否存在动画

- (void)setValue:(float)value animated:(BOOL)animated


三,UISliderDemo

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(60, 100, 200, 20)];
    slider.tag = 101;
    slider.maximumValue = 10;
    slider.minimumValue = 0;
//    [slider addTarget:self action:@selector(change:) forControlEvents:UIControlEventValueChanged];
//    [slider addTarget:self action:@selector(touchUpInside:) forControlEvents:UIControlEventTouchUpInside];
    [slider addTarget:self action:@selector(test1) forControlEvents:UIControlEventTouchDragInside];
    [slider addTarget:self action:@selector(test2) forControlEvents:UIControlEventTouchDragOutside];
//    slider.value = 5; // 0 ~ 1
    [self.window addSubview:slider];
    [slider release];
    
//    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(test:) userInfo:slider repeats:NO];
    
    return YES;
}

- (void)test:(NSTimer *)timer
{
    UISlider *slider = [timer userInfo];
    [slider setValue:5 animated:NO];
}

- (void)change:(UISlider *)slider
{
    NSLog(@"slider value : %.2f", slider.value);
}

- (void)touchUpInside:(UISlider *)slider
{
    NSLog(@"touchUpInside : %.2f", slider.value);
}

- (void)test1
{
    NSLog(@"test1");
}

- (void)test2
{
    NSLog(@"test2");    
}



阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/LG_CodeMachine/article/details/51555100
个人分类: iOS控件大全
所属专栏: iOS控件大全
上一篇iOS控件之UITextField
下一篇iOS控件之UISegmentedControl
想对作者说点什么? 我来说一句

UISlider Demo代码

2013年04月24日 70KB 下载

没有更多推荐了,返回首页

关闭
关闭