There are two ways to set a background image to a UIView –
- You can set your view background color to color created with UIColor’s colorWithPaternImage.
- You can add a UIImageView subview to your view.
colorWithPaternImage was created to use small images to create a pattern image that will be repeated. Using it with large images wont be a wise decision. So if you want to have a patterned image background with uses small images which will be repeated to fill the background, then you should use colorWithPaternImage, as it will do it quickly and wont consume much memory.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background"]];
If you have a full size background image, then you should definitely use the UIImageView. Using UIImageView will save a lot of memory in this case.
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background"]];
How to Add Background Image to UIKit Controls
To bring appearance changes to UIKIT controls, you can use the Apple Appearance API, which was introduced with iOS5. Using Appearance API, you can set the tint color, background image, and title position properties (among other) on a wide variety of objects, including toolbars, navigation bars, search bars, buttons, sliders, and some other controls.
For example, to add a background image to Navigation Bar, you can use the following code –
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav_bar"] forBarMetrics:UIBarMetricsDefault];
Have a look at this link to get more info on Appearance API.