Search code examples
objective-ciosuiimagecore-graphicsuicolor

Setting a UIImage as Background - NOT Tiled


I have a Background Image Picker that lets the user select from stock images of from their Album. To set the Image I have the Following code:

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

Though the Images are always tiled starting form the Top Right. This works great for my 32x32 patterns, though if a User wants to use a 1024x768 Image on a 2048x2048 canvas and does not want it to tile, how can I prevent the tile?

My Only thought was to convert the Smaller Image to one that is the size of the Canvas, then set it to that.

Any Other Suggestions?


Solution

  • You could always subclass UIView and use CoreGraphics to draw the image in -drawRect: