Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xcode 图像位置_Xcode_Uiimage - Fatal编程技术网

Xcode 图像位置

Xcode 图像位置,xcode,uiimage,Xcode,Uiimage,我使用以下代码在UIView中放置一些图像: UIImage *image; UIGraphicsBeginImageContext(CGSizeMake(480, 320)); int k=0; int posY=0; for (int i=0; i<[theArray count]; i++) { image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[theArray objectAtIndex:i]]];

我使用以下代码在UIView中放置一些图像:

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

for (int i=0; i<[theArray count]; i++) {

    image=[UIImage imageNamed:[NSString stringWithFormat:@"%@",[theArray objectAtIndex:i]]];
    if (k>2) {
        k=0;
        posY++;
    }       

    [image drawAtPoint:CGPointMake(k*64, posY*23)];

    k++;

}


UIImage *combinatedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImage*图像;
UIGraphicsBeginImageContext(CGSizeMake(480320));
int k=0;
int-posY=0;
对于(int i=0;i2){
k=0;
posY++;
}       
[图像绘制点:CGPointMake(k*64,posY*23)];
k++;
}
UIImage*combinatedImage=UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsSendImageContext();
获取此结果:

但是我想得到这个:

我搞不懂,我太糊涂了

谁能帮帮我吗


谢谢

如果图像的最后一行少于三行,则需要向其添加X偏移:

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++;
}

for(int i=0;iThanks用于回复。但是您的代码生成了此图像,但我希望类似这样