2 daffodilgirl DaffodilGirl 于 2013.06.13 16:03 提问

在图片中添加空白区域

写了一个循环来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个回答

xinyoulingxi1_tong
xinyoulingxi1_tong   2013.06.13 16:57
已采纳

添加到currentY中:

currentY += imageView.frame.size.height + 12.0f;
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!