How To Set The Background Image For Your iOS App?

When you are designing your iOS app, you cant help but think about the aesthetics. You want to present your app in the best possible way. There are some things you cant ignore, like the icon, or the background, or the first screen. These are the things that tend to impact your app the most. Although the functionality is the most important part, a new user will not get there if you don’t make your app look aesthetically pleasing. A new user doesn’t know what your app does, so you should give the user a strong reason to keep going. The background image is one of the key aspects in your app. There are two ways of setting the background image.  

Using UIImageView

Add “imageName.png” to the project by right-clicking and adding to the main folder. Add “Image View” to your XIB file. Then go to the view and add the following:

CurrentImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"imageName.png"]];
CurrentImage.frame = self.view.bounds;
[[self view] addSubview:CurrentImage];
[CurrentImage.superview sendSubviewToBack:CurrentImage];

Using UIColor

Setting the image using UIColor is a bit more rigid, so use this if you want a constant background. It’s not that you can’t change it, but if you want something more flexible, it’s better to use UIImageView.

Add “imageName.png” to the project by right-clicking and adding to the main folder. Then go to the view and add the following:

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imageName.png"]];

It should look like this:

@implementation MyViewController
-(IBAction)MyButton:(id)sender{
    MyViewName *FirstToSecond = [[MyViewName alloc] initWithNibName:@"MyViewName" bundle:nil];
    FirstToSecond.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imageName.png"]];
    [self.view addSubview:FirstToSecond.view];
}
@end

Also, to change the main view background image, add it to viewDidLoad:

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

————————————————————————————————-

One thought on “How To Set The Background Image For Your iOS App?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s