Tiling an image background in an iOS application

To change the background image of an iOS application, one of the simplest methods is to add a UIImageView component onto the application, set its Image property and then send the UIImageView to the background.

This technique works well and doesn’t require any coding, but the image has to be big enough to cover the entire  screen area of the application.  The image can be stretched to cover the application background, but not tiled. Sometimes this looks OK, but if you want to tile and image onto the applications background, setting the application’s bachgroundColor (yes, color!) property is what’s needed.

In the view’s controller class, add a viewDidLoad method and set the view’s backgroundColor property to a UIColor instantiated with the colorWithPatternImage selector. For example,

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor =
        [UIColor colorWithPatternImage: [UIImage imageNamed:@"tile.png"]];
}

Leave a comment