UIImage位置 [英] UIImage position

查看:18
本文介绍了UIImage位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 (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();

得到这个结果:

Obtaining this result:

但我想获得这个:

But I would like to obtain this:

我不明白,我很困惑.

有人可以帮我吗???

谢谢!!

推荐答案

如果最后一行图像少于三个,则需要在最后一行添加 X 偏移量:

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

这篇关于UIImage位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆