我遵循user2207904的代码
在 viewDidLoad 我创建了 20 个滑块和 20 个标签
然后我的 20 个标签采用我的推子的值(label.text= [NSString stringWithFormat:@"%i", slvalue];)
但是如果我移动我的标签不遵循我的推子值,就像这样......
我怎样才能按照我的推子值来处理我的标签?
我的代码
- (void)viewDidLoad
{
[super viewDidLoad];
for(int i=0; i< 20; i++){
//sliders
UISlider *slider = [[[UISlider alloc] initWithFrame:CGRectMake(1+i*50, 450, 300, 10)] autorelease];
slider.minimumValue = 1;
slider.maximumValue = 100;
slider.continuous = YES;
[self.view addSubview:slider];
slider.transform = CGAffineTransformRotate(slider.transform, 270.0/180*M_PI);
[slider setThumbImage:thumbImage0 forState:UIControlStateNormal];
[slider release];
// label
UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(1+i*50, 640, 40, 15)];
int slvalue = slider.value;
label.text= [NSString stringWithFormat:@"%i", slvalue];
[self.view addSubview:label];
[label release];
}
新问题 :
修改的
我这样做:
我在我的 FirstViewController.m 中放了一个 IBAction
- (IBAction)sliderUpdate:(UISlider *)sender {
self.label.text = [NSString stringWithFormat:@"%g", sender.value];
}
并将其放入我的 viewDidLoad (FirstViewController.m)
{
[super viewDidLoad];
for(int i=0; i< 20; i++){
//sliders
UISlider *slider = [[[UISlider alloc] initWithFrame:CGRectMake(1+i*50, 450, 300, 10)] autorelease];
slider.minimumValue = 1;
slider.maximumValue = 100;
slider.continuous = YES;
[slider addTarget:self action:@selector(sliderUpdate:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:slider];
slider.transform = CGAffineTransformRotate(slider.transform, 270.0/180*M_PI);
[slider setThumbImage:thumbImage0 forState:UIControlStateNormal];
[slider release];
// label
UILabel *label = [[UILabel alloc] initWithFrame: CGRectMake(1+i*50, 640, 40, 15)];
int slvalue = slider.value;
label.text= [NSString stringWithFormat:@"%i", slvalue];
[self.view addSubview:label];
[label release];
}
我的(IBAction)sliderUpdate 中有此错误: 在“FirstViewController *”类型的对象上找不到属性“标签”