2011-06-01 86 views
0

在iPhone上,我想一次显示13张图像,每行显示13张图像。我设法获得了4张图像的第一排,但其余的我都遇到了麻烦。这是我到目前为止:在iphone上制作照片库

NSInteger startPoint = 10; 
     for (int i=0; i<13; i++) 
     { 
      UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
      [btn setImage:[self getImageFromName:@"headshotsmile"] forState:UIControlStateNormal]; 
      btn.frame = CGRectMake(startPoint, 10, 40, 40); 
      startPoint = startPoint + 40 + btn.frame.size.width; 
      [self.view addSubview:btn]; 

如何让其余的图像显示?

回答

0
CGPoint startPoint = CGPointMake(10, 10); 
for (int i = 0; i < 13; i++) { 
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom]; 
    [btn setImage:[self getImageFromName:@"headshotsmile"] forState:UIControlStateNormal]; 
    btn.frame = CGRectMake(startPoint.x, startPoint.y, 40, 40); 
    startPoint.x += 40 + btn.frame.size.width; 
    if (i % 4 == 3) { 
     startPoint.x = 10; 
     startPoint.y += 40 + btn.frame.size.height; 
    } 
    [self.view addSubview:btn]; 
} 

的关键在这里是每当i等于3模4,你只需移动startPoint到下一行的开始。

+0

感谢它的工作 – 2011-06-01 11:17:08