2011-06-01 81 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