我用ipad的scrollview创建缩略图照片,这是代码:
// load all the images from bundle and add them to the scroll view
NSUInteger i;
for (i = 1; i <= kNumImages; i++)
{
NSString *imageName = [NSString stringWithFormat:@"image%d.jpg", i];
UIImage *image = [UIImage imageNamed:imageName];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
}
- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollView1 subviews];
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += (kScrollObjWidth);
}
}
}
右边我在UIScrollView中的所有图像都是彼此相邻的,我希望每张图像之间有一些空间,比如这张图片
请你给我一些提示,告诉我如何在这些图像之间添加空间?
提前致谢!
答案 0 :(得分:0)
试试这个:
curXLoc += (kScrollObjWidth) + kDifferenceBetweenImages;
并相应地定义kDifferenceBeteweenIMages。
答案 1 :(得分:0)
请改用UICollectionView。更容易实现你想要的东西,也会更好地工作。
它甚至具有每个单元格之间空间的属性。
答案 2 :(得分:0)
试试这个:
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
frame.size.height = //put height;
frame.size.width = //put width;
frame.origin.y = //put y;
view.frame = frame;
curXLoc += (kScrollObjWidth) + 15;