UIImage position

前端 未结 1 858
情话喂你
情话喂你 2021-01-29 08:55

I\'m using the following code to place some images in the UIView:

UIImage *image;
UIGraphicsBeginImageContext(CGSizeMake(480, 320));
int k=0;
int posY=0;

for (i         


        
相关标签:
1条回答
  • 2021-01-29 09:40

    You need to add an X offset to your last line of images if it has less than three:

    for (int i=0; i<[theArray count]; i++) {
    
        int imagesLeft = min(3, [theArray count] - i);
        int offs = (3 - imagesLeft) * 64 / 2;
    
        for (int k = 0; k < imagesLeft; k++) {
            image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[theArray objectAtIndex:i]]];
            [image drawAtPoint:CGPointMake(k*64 + offs, posY*23)];
        }
        posY++;
    }
    
    0 讨论(0)
提交回复
热议问题