- (void)viewDidLoad {
[super viewDidLoad];
self.sp = [[UIStepper alloc]init];
//设置计步器的位置
self.sp.center = CGPointMake(100, 100);
//计步器最小值和最大值
self.sp.minimumValue = 0;
self.sp.maximumValue = 10;
//设置计步器步值
self.sp.stepValue = 1.0;
//是否按着持续改变值
self.sp.autorepeat = YES;
//添加点击事件
[self.sp addTarget:self action:@selector(valueChange:) forControlEvents: UIControlEventTouchUpInside ];
[self.view addSubview:self.sp];
//设置滑动器
self.sd = [[UISlider alloc]init];
self.sd.center = CGPointMake(200, 300);
self.sd.maximumValue = 100;
self.sd.minimumValue = 10;
//滑动器两边的样式
self.sd.minimumTrackTintColor = [UIColor redColor];
self.sd.maximumTrackTintColor = [UIColor blueColor];
//两边可以设置图片
self.sd.minimumValueImage = [UIImage imageNamed:@""];
self.sd.maximumValueImage = [UIImage imageNamed:@""];
//添加滑动事件
[self.sd addTarget:self action:@selector(valueChange1:) forControlEvents: UIControlEventTouchUpInside ];
[self.view addSubview:self.sd];
}
//均是值的改变
-(void)valueChange:(UIStepper*)sp{
NSLog(@"%f",sp.value);
}
-(void)valueChange1:(UISlider*)sd{
NSLog(@"%f",sd.value);
}
#pragma mark - 开关空间的属性及开和关
-(void)switchValueChanged:(UISwitch *)sw
{
if(sw.on)
{
NSLog(@"开");
}
else
{
NSLog(@"关");
}