在scrollview中获取图像标记

时间:2012-03-09 03:21:00

标签: ios uiscrollview tags

我使用以下代码创建了一个scrollview:

NSUInteger i;
for (i = 1; i <= kNumImages; i++)
{
    imageName = [NSString stringWithFormat:image, i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

    CGRect rect = imageView.frame;
    rect.size.height = kScrollObjHeight;
    rect.size.width = kScrollObjWidth;
    imageView.frame = rect;
    imageView.tag = i;  // tag our images for later use when we place them in serial fashion
    [bigScrollView addSubview:imageView];
}

如何在视图中获取当前图片的标记?

1 个答案:

答案 0 :(得分:1)

您可以通过获取bigScrollView的所有子视图来获取标记。

 for(UIView *subview in [bigScrollView subviews])
 {
     if([subview isKindOfClass:[UIImageView class]])
     {
         NSLog("%d",[subview tag]);
     }
 }