gpt4 book ai didi

iphone - 如何在 ImageView 中设置图像标签?

转载 作者:行者123 更新时间:2023-12-03 21:06:30 24 4
gpt4 key购买 nike

- (void)viewDidLoad {
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)];
tapGesture.numberOfTapsRequired = 1;
tapGesture.numberOfTouchesRequired = 1;

self.title=@"Evolution";
scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];

int numberOfImages = 32;
CGFloat currentX = 0.0f;

for (int i=1; i <= numberOfImages; i++) {

// create image
NSString *imageName = [NSString stringWithFormat:@"page-%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
imageView = [[UIImageView alloc] initWithImage:image];

// put image on correct position
CGRect rect = imageView.frame;
rect.origin.x = currentX;
imageView.frame = rect;
imageView.tag=i;
// update currentX
currentX +=454; //mageView.frame.size.width;

[scrollView addSubview:imageView];
[imageView release];
}
[scrollView addGestureRecognizer:tapGesture];

scrollView.contentSize = CGSizeMake(currentX, 800);
scrollView.pagingEnabled=YES;
scrollView.userInteractionEnabled = YES;
scrollView.maximumZoomScale = 15;
scrollView.minimumZoomScale = 0.5;
scrollView.bounces = NO;
scrollView.bouncesZoom = NO;
scrollView.delegate = self;

scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:scrollView];
[scrollView release];
[super viewDidLoad];
}

在上面的代码中如何为每个图像设置标签?这样我就可以使用该标签从网络服务调用更大的图像作为引用。

最佳答案

imageView.image.tag=i;

或者

[imageView.image setTag:i];

关于iphone - 如何在 ImageView 中设置图像标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6634341/

24 4 0