如何在图像之间添加空白?

时间:2013-06-12 11:44:05

标签: iphone objective-c uiimageview uiimage

我编写了一个循环代码,用于在scrollview内的UIImageView上创建多个图像。我做了这样的事情:

UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(38, 9, 90, 280)];
int numberOfImages = 9;
CGFloat currentY = 0.5f;

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

    NSString *imageName = [NSString stringWithFormat:@"img0%d.jpg",i];
    UIImage *image = [UIImage imageNamed:imageName];
    UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
    imageView.frame = CGRectMake(2, 15, 87, imageView.frame.size.height - 20);

    CGRect rect = imageView.frame;
    rect.origin.y = currentY;
    imageView.frame = rect;

    currentY += imageView.frame.size.height;
[scrollView addSubview:imageView];
}
scrollView.contentSize = CGSizeMake(87,currentY);
[self.view addSubview:scrollView];

现在,我需要在每个图像之间添加一个空格,我该怎么做?

1 个答案:

答案 0 :(得分:4)

再添加一点currentY

currentY += imageView.frame.size.height + 12.0f;