简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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