简体   繁体   English

在滚动视图中获取图像标签

[英]Get tag of images in scrollview

I have a scrollview created using the following code: 我有一个使用以下代码创建的滚动视图:

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];
}

How can I get the tag of the image currently in the view? 如何获取视图中当前图像的标签?

You can get the tag by getting all the subviews of bigScrollView. 您可以通过获取bigScrollView的所有子视图来获取标签。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM