我是 iOS 开发的新手,我制作了一个包含 ScrollView 的应用程序,并在 scrollview 中添加了一个数组图像,但它不起作用。
我为此写了一个代码
for(int index=0; index < [self.imagesa count]; index++)
{
NSDictionary *dict=[self.imagesa objectAtIndex:index];
NSString *image=[dict valueForKey:@"link"];
UIImageView *bigImage=[[UIImageView alloc]init];
bigImage.bounds=CGRectMake(0, 0, self.zoomScroll.frame.size.width, self.zoomScroll.frame.size.height);
bigImage.frame=CGRectMake(0, 0, self.zoomScroll.frame.size.width, self.zoomScroll.frame.size.height);
[bigImage sd_setImageWithURL:[NSURL URLWithString:image] placeholderImage:[UIImage imageNamed:@"1.png"]];
[self.objectarray insertObject:bigImage atIndex:index];
CGSize scrollViewSize=CGSizeMake(self.zoomScroll.frame.size.width*[self.objectarray count], self.zoomScroll.frame.size.height);
[self.zoomScroll setContentSize:scrollViewSize];
[self.zoomScroll addSubview:bigImage];
[self.zoomScroll addSubview:[self.objectarray objectAtIndex:index]];
}
它是将我的所有图像添加到一个 ImageView 中。不是 Scrollview 中的一个一个,请给我解决方案
这里的对象数组是 NSMutableArray 数组,imagesa 也是 NSMutableArray,它包含图像 URLlink。
最佳答案
查看“bigImage.frame”的 X 坐标。您在同一坐标上添加图像,一个在另一个之上。应该是……
bigImage.frame=CGRectMake(index * self.zoomScroll.frame.size.width, 0, self.zoomScroll.frame.size.width, self.zoomScroll.frame.size.height);
关于ios - 如何将图像数组添加到 UIScrollView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26858183/