Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Repeating background image in native iPhone app

Short of putting a UIWebView as the back-most layer in my nib file, how can I add a repeating background image to an iPhone app (like the corduroy look in the background of a grouped UITableView)?

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

like image 642
Frank Schmitt Avatar asked Oct 22 '08 04:10

Frank Schmitt


People also ask

How do I stop my background image from repeating?

To make a background image not repeat in HTML, specify no-repeat in the background-repeat property or the background shorthand property. The background image is set to 'no-repeat' using the 'background-repeat' property. The above example uses the background-repeat property to set the image to no-repeat .

How do you call a background image in react native?

Style: import React from 'react-native'; let { StyleSheet } = React; let styles = StyleSheet. create({ backgroundImage: { flex: 1, resizeMode: 'cover', // or 'stretch' } });


1 Answers

Apparently a UIColor is not necessarily a single color, but can be a pattern as well. Confusingly, this is not supported in Interface Builder.

Instead you set the backgroundColor of the view (say, in -viewDidLoad) with the convenience method +colorWithPatternImage: and pass it a UI Image. For Instance:

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

Of course, don't forget to add the image file to your application bundle.

There are also some built-in background pattern "colors":

  • groupTableViewBackgroundColor
  • viewFlipsideBackgroundColor

Because the are used globally across all iPhone apps, you incur the double-edged sword of an OS update updating the look and feel of your application (giving it a fresh new look that may or may not work right).

For instance:

- (void)viewDidLoad {     [super viewDidLoad];     self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];  } 
like image 113
Frank Schmitt Avatar answered Sep 20 '22 13:09

Frank Schmitt