-(void) addImageviewsToscrollview {
int cx = 0;
for (int i = 0; i < 4; i++) {
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"placeholder.png"]];
CGRect rect = imageView.frame;
rect.size.height = 100;
rect.size.width = 100;
rect.origin.x = cx;
rect.origin.y = 0;
imageView.tag = i;
imageView.frame = rect;
[self.imageScrollview addSubview:imageView];
cx += imageView.frame.size.width+25;
}
[self.imageScrollview setContentSize:CGSizeMake(cx, [self.imageScrollview bounds].size.height)];
}
将ImageView添加到ScrollView。应用程序仅用于iPad,我使用的是故事板。我应该创建一个新类和一个新的UIViewController吗?
答案 0 :(得分:2)
如果您想要使用任何标记访问任何UIImageView
,请使用viewWithTag:
UIImageView *imageView = (UIImageView *)[self.imageScrollview viewWithTag:1];
只需使用您的代码更改数字1。
答案 1 :(得分:0)
尝试通过启动1添加标记 imageView.tag = i + 1;