IOS Slider控件

//初始化slider

UISlider *slider=[[UISlider alloc]initWithFrame:CGRectMake(60,100,200,30)];  

slider.tag=101;//tag值

//设置最大值

slider.maximumValue=1;

//设置最小值

slider.minimumValue=0;

//设置默认值

slider.value=0.8f;

//设置值(带有动画)

//[slider setValue:.5 animated:YES];

//添加事件

[slider addTarget:self action:@selector(valueChange:) forControlEvents:(UIControlEventValueChanged)];

//把slider添加到视图上进行显示

[self.window addSubview:slider];   

[slider release];//mrc下(arc下不需要手动释放)

//[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(test:) userInfo:slider repeats:YES];

[self.window makeKeyAndVisible];returnYES;}

-(void)valueChange:(UISlider *)slider{   

NSLog(@"slider value : %.2f",[slidervalue]);

}

//NSTimer(定时器)

-(void)test :(NSTimer *)timer{   

UISlider *slider=timer.userInfo;   

[slider setValue:0.5f animated:YES];

}

//此外slider还有两个属性

@property(nonatomic,retain) UIImage *minimumValueImage;

// default is nil. image that appears to left of control (e.g. speaker off)

@property(nonatomic,retain) UIImage *maximumValueImage;

你可能感兴趣的:(IOS Slider控件)