Repeated background image in iPhone app

If you are not using UIWebView as the last layer in my nib file, how do I add a repeating background image to my iPhone application (for example, a corduroy look against a grouped UITableView)?

Do I need to create an image the size of the iPhone screen and manually repeat it using copy and paste?

+47
iphone cocoa-touch native repeat
Oct 22 '08 at 4:38
source share
4 answers

Apparently, UIColor is not necessarily the only color, but it can be a template. Confusingly, this is not supported in Interface Builder.

Instead, you set the backgroundColor of the view (for example, to -viewDidLoad) using the convenience method + colorWithPatternImage: and pass it the image of the user interface. For instance:

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

Of course, be sure to add the image file to your application package.

There are also some built-in background colors:

  • groupTableViewBackgroundColor
  • viewFlipsideBackgroundColor

Since they are used globally in all iPhone applications, you take the double-edged sword of OS updates, updating the look of your application (giving it a new look that may or may not work correctly).

For example:

 - (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor = [UIColor groupTableViewBackgroundColor]; } 
+160
Oct 22 '08 at 4:48
source share

You should take a look at the Apple iPhone QuartzDemo sample code, specifically QuartzImageDrawing.m. Must use the following method call.

 CGContextDrawTiledImage 
+2
Oct 22 '08 at 9:12
source share

You can even have animated fake background images that move .: D

Amuck Apps contains a simple tutorial that shows you how to do this on your website.

31 Days iPhone Apps - Day 16: World Tour

+2
Oct 22 '08 at 16:51
source share

You should use colorWithPatternImage

+1
Jul 13 '10 at 4:15
source share



All Articles