Wednesday, May 4, 2011

How To: Have Cool Backgrounds From Code

iOS stocks some built in backgrounds images ready to be used by any objects that has a UIColor property. Ever wonder how to get them? One way is to capture the screen when it is showing on the iphone (by pressing home + power button simultaneously), copy the pattern and fill an image with it as your own custom.png background image. But wait, there is a much simpler, easier way.

This blog post is a simple and straightforward tutorial, therefore no downloadable sample code.

Try to create a View based project and add the following code at viewDidLoad.
 self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
//self.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
//self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];

These will give your view a standard Apple's OS backgrounds image texture that we always see.
So you do not need to make it your own, wasting resources.

For your reference, here is what each "color" give:




Cool eh?