目标c-在iphone中制作一个照片库



在iPhone上,我想一次显示13张图像,每行显示4张。我已经设法得到了4个图像的第一排,但我在其他方面遇到了麻烦

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

如何显示其余图像?

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移动到下一行的开头。

相关内容

  • 没有找到相关文章

最新更新