2013-06-12 2 views
0

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]; 

지금, 나는 각 이미지 사이에 공백을 추가해야하나요, 어떻게해야합니까?

+0

당신의 필요에 따라 y 좌표를 변경하려고합니다. 간단합니다 ... –

+0

일부 논리를 적용 할 수 있습니까? 끔찍한 독트린, 초등 기하학? –

+3

또한 Xcode와 관련이 없습니다. –

답변

4

currentY에 조금 더 추가 하시겠습니까?

currentY += imageView.frame.size.height + 12.0f; 
관련 문제