在总结4的基础上创建一个Slider,添加代码如下:
- (void)viewDidLoad
{
//....
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(40.0, 200.0, 240.0, 20.0)];
slider.minimumValue = 0;
slider.maximumValue = 100;
slider.value = 50;
[slider addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged];
[[self view] addSubview:slider];
[slider release];
}
{
//....
UISlider *slider = [[UISlider alloc] initWithFrame:CGRectMake(40.0, 200.0, 240.0, 20.0)];
slider.minimumValue = 0;
slider.maximumValue = 100;
slider.value = 50;
[slider addTarget:self action:@selector(sliderValueChange:) forControlEvents:UIControlEventValueChanged];
[[self view] addSubview:slider];
[slider release];
}
事件实现:
- (void)sliderValueChange:(id)sender
{
UISlider *sli = (UISlider *)sender;
resultLbl.text = [NSString stringWithFormat:@"%.2f",sli.value];
}
{
UISlider *sli = (UISlider *)sender;
resultLbl.text = [NSString stringWithFormat:@"%.2f",sli.value];
}
求规范,求指点。谢谢!