Objective c 将UIImage设置为背景-未平铺

Objective c 将UIImage设置为背景-未平铺,objective-c,ios,uiimage,core-graphics,uicolor,Objective C,Ios,Uiimage,Core Graphics,Uicolor,我有一个背景图像选择器,允许用户从相册中的股票图像中进行选择。要设置图像,我有以下代码: -(void)setBackgroundImage:(UIImage *)newImage { [backgroundImage release]; backgroundImage = newImage; [backgroundImage retain]; [editorContentView setBackgroundColor:[UIColor colorWith

我有一个背景图像选择器,允许用户从相册中的股票图像中进行选择。要设置图像,我有以下代码:

-(void)setBackgroundImage:(UIImage *)newImage {    
    [backgroundImage release];
    backgroundImage = newImage;
    [backgroundImage retain];
    [editorContentView setBackgroundColor:[UIColor colorWithPatternImage:newImage]];
}  
尽管图像总是从右上角开始平铺。这对于我的32x32模式非常有效,但是如果用户希望在2048x2048画布上使用1024x768图像,并且不希望它平铺,我如何防止平铺

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


还有其他建议吗?

您可以始终将UIView子类化并使用CoreGraphics在-drawRect中绘制图像:

您可以始终将UIView子类化并使用CoreGraphics在-drawRect中绘制图像:

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

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

谢谢,我在drawRect中得到了以下提示:`if(tileBackgroundImage){CGRect bounds=self.bounds;[backgroundImage DrawAsPatterInRect:bounds];}else{[self-setBackgroundColor:[UIColor blackColor]];[backgroundImage-drawAtPoint:CGPointZero];}谢谢,我在drawRect中得到了以下信息:`if(tileBackgroundImage){CGRect-bounds=self.bounds;[backgroundImage-drawaspatternot:bounds];}else{[self-setBackgroundColor:[UIColor blackColor]];[backgroundImage drawAtPoint:CGPointZero];}`