iOS 101: Pattern Images

by Bob McCune on March 8, 2011

A common need in an iOS app is to tile a background image on a UIView. It’s trivial to implement, but not particularly obvious if you’re new to the platform. The solution is to set the view’s backgroundColor property to a UIColor instance created from your pattern image. For instance, the following code will create a pattern image from pattern.png:

This will produce the following effect:

Like most things in Cocoa there is usually an easy solution to the problem you’re trying to solve, but what it is may not be immediately apparent if you’re just starting out. Hope this helps.