0

我有一个背景图像选择器,可让用户从相册中的库存图像中进行选择。要设置图像,我有以下代码:

-(void)setBackgroundImage:(UIImage *)newImage {    
    [backgroundImage release];
    backgroundImage = newImage;
    [backgroundImage retain];
    [editorContentView setBackgroundColor:[UIColor colorWithPatternImage:newImage]];
}  

虽然图像总是从右上角开始平铺。这对我的 32x32 模式非常有用,但如果用户想在 2048x2048 画布上使用 1024x768 图像并且不希望它平铺,我该如何防止平铺?

我唯一的想法是将较小的图像转换为画布大小的图像,然后将其设置为该大小。

还有其他建议吗?

4

2 回答 2

2

将背景设置为透明并创建一个单独的UIImageView,然后您可以将其放在下面。

于 2012-06-05T18:57:46.087 回答
1

你总是可以继承 UIView 并使用 CoreGraphics 在 -drawRect 中绘制图像:

于 2012-06-05T18:54:02.903 回答