gpt4 book ai didi

ios - 获取 ScrollView 中图像的标签

转载 作者:行者123 更新时间:2023-11-29 04:46:04 25 4
gpt4 key购买 nike

我使用以下代码创建了一个 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];
}

如何获取 View 中当前图像的标签?

最佳答案

可以通过获取bigScrollView的所有 subview 来获取标签。

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

关于ios - 获取 ScrollView 中图像的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9628481/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com