我使用 for 循环在滚动条上创建了多个图像和滑块,如何通过更改滑块的值来更改图像的 alpha?这是我尝试在函数 loadImages 之外声明 uiimages 的代码,但我认为这不是一个好主意。我知道如何在不使用 for 循环的情况下做到这一点,但是如果我想使用 for 循环,我怎样才能让函数知道它应该对哪个 uiimage 进行操作。因为我认为在 for 循环中创建的所有 uiimage 都不是公共对象。
-(void)loadImages
{
for (int i = 0; i < 10; i++){
//show drawing position in the output
NSLog(@"x:%i, y:%i",xInc, yInc);
//text label on the slider button
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(78 + xInc, 55+yInc, 200, 20)];
Person *thisPerson = [arrayOfPerson objectAtIndex:i];
NSString *namePerson = thisPerson.name;
[label setText:[NSString stringWithFormat:@"%@",namePerson]];
[label setTextColor:[UIColor whiteColor]];
[label setBackgroundColor:[UIColor clearColor]];
label.textAlignment = NSTextAlignmentCenter;
//front office background image of slider
NSString *frontimageName = [NSString stringWithFormat:@"frontofficeBUTTON.png"];
UIImageView *frontimgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:frontimageName]];
frontimgView.frame = CGRectMake(xInc, 10 + yInc, 332, 70);
[frontimgView setTag:i];
//back office background image of slider
NSString *backimageName = [NSString stringWithFormat:@"backofficeBUTTON.png"];
UIImageView *backimgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:backimageName]];
backimgView.frame = CGRectMake(xInc, 10 + yInc, 332, 70);
[backimgView setTag:i];
//slider
UISlider *slider=[[UISlider alloc] initWithFrame:CGRectMake(5+ xInc, 25+yInc, 322, 40)];
//give a id tag to the slider
[slider setTag:i];
//set a action to the slider
[slider addTarget:self action:@selector(UnlocklinkSlider:) forControlEvents:UIControlEventTouchUpInside];
//define the appearance of the slider
UIImage *stetchLeftTrack= [[UIImage imageNamed:@"Nothing.png"]
stretchableImageWithLeftCapWidth:30.0 topCapHeight:0.0];
UIImage *stetchRightTrack= [[UIImage imageNamed:@"Nothing.png"]
stretchableImageWithLeftCapWidth:30.0 topCapHeight:0.0];
[slider setThumbImage: [UIImage imageNamed:@"rightBUTTON.png"] forState:UIControlStateNormal];
[slider setMinimumTrackImage:stetchLeftTrack forState:UIControlStateNormal];
[slider setMaximumTrackImage:stetchRightTrack forState:UIControlStateNormal];
yInc = yInc + 80;
[_scrollView addSubview:backimgView];
[_scrollView addSubview:frontimgView];
[_scrollView addSubview:label];
[_scrollView addSubview:slider];
}
[_scrollView setContentSize:CGSizeMake(320, scrollLength)];
}
- (void)UnlocklinkSlider:(UISlider*)slider
{...}