在iOS中是⼀个滑块控件,基本⽤于视频播放进度,控制⾳量⼤⼩,控制播放器的进度条等等。
UISlider继承于UIControl,拖动UISlider时,会提供⼀系列的值,滑块在不同的
位置,获取的值也是不同的。
//
// ViewController.m
// UISlider01
//
// Created by cqy on 16/2/15.
// Copyright © 2016年 程清杨. All rights reserved.
//
#import "ViewController.h"
@interface ViewController (){
UISlider *slider;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//slider进度条
//创建slider
slider = [[UISlider alloc]initWithFrame:CGRectMake(50, 200, 200, 50)];
//设置最⼩值 负数也可以
slider.minimumValue = 0;
//最大值
slider.maximumValue = 1;
//当前值
slider.value = 0.5;
//划过领域
slider.minimumTrackTintColor = [UIColor greenColor];
//未划过的领域
slider.maximumTrackTintColor = [UIColor grayColor];
//⼩圆点变颜⾊(进度条上当前位置⼩圆点的颜⾊(想要把⼩圆点的颜⾊改变,得⾸先把这个⼩圆点⽤图⽚来代替:调setThumbImage⽅法))
slider.thumbTintColor = [UIColor redColor];
//设置图⽚后,⼩圆点才会变颜⾊
// [slider setThumbImage:[UIImage imageNamed:@"slider"] forState:UIControlStateNormal];
// 最⼩值图⽚
// slider.minimumValueImage = [UIImage imageNamed:@"slider.png"];
// 最⼤值图⽚
//slider.maximumValueImage = [UIImage imageNamed:@"slider02.png"];
//添加滑动事件
[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:slider];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)sliderAction:(UISlider *)sender{
NSLog(@"%lf",sender.value);
// 使⽤slider的值,改变视图透明度sender.value:为当前值sender.value为当前值
self.view.alpha = sender.value;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
// ViewController.m
// UISlider01
//
// Created by cqy on 16/2/15.
// Copyright © 2016年 程清杨. All rights reserved.
//
#import "ViewController.h"
@interface ViewController (){
UISlider *slider;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//slider进度条
//创建slider
slider = [[UISlider alloc]initWithFrame:CGRectMake(50, 200, 200, 50)];
//设置最⼩值 负数也可以
slider.minimumValue = 0;
//最大值
slider.maximumValue = 1;
//当前值
slider.value = 0.5;
//划过领域
slider.minimumTrackTintColor = [UIColor greenColor];
//未划过的领域
slider.maximumTrackTintColor = [UIColor grayColor];
//⼩圆点变颜⾊(进度条上当前位置⼩圆点的颜⾊(想要把⼩圆点的颜⾊改变,得⾸先把这个⼩圆点⽤图⽚来代替:调setThumbImage⽅法))
slider.thumbTintColor = [UIColor redColor];
//设置图⽚后,⼩圆点才会变颜⾊
// [slider setThumbImage:[UIImage imageNamed:@"slider"] forState:UIControlStateNormal];
// 最⼩值图⽚
// slider.minimumValueImage = [UIImage imageNamed:@"slider.png"];
// 最⼤值图⽚
//slider.maximumValueImage = [UIImage imageNamed:@"slider02.png"];
//添加滑动事件
[slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:slider];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)sliderAction:(UISlider *)sender{
NSLog(@"%lf",sender.value);
// 使⽤slider的值,改变视图透明度sender.value:为当前值sender.value为当前值
self.view.alpha = sender.value;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end