iOS - Set a pattern background image for a UIView

In iOS, there is no way to slug a background image into a UIView - making it slightly trickier to style your new iOS application background (and who doesn’t like the new iOS 5 linen?). However, you can apply a UIColor. Did you know UIColor can be a pattern? And the pattern can be defined by a UIImage? Well, it can, and here is a one-liner to do so:

self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bgs/fileinbundle.png"]];

(This code depends on ARC in XCode 4.2+ - apply reference counting as appropriate for other versions) Please note that you have to set all the items which are in front of the background view to clearColor such that they will not cover the background image.