Share Coding

Tutorials, Problems, Stuffs …

Make Background Image Fitting to the UIView

1.             Too Small                                    Too Large                                What we want
Too SmallToo LargeFit

2. To make a centered and stretched image:

UIGraphicsBeginImageContext(self.view.frame.size);
[[UIImage imageNamed:@"image.png"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

self.view.backgroundColor = [UIColor colorWithPatternImage:image];
Advertisements

3 responses to “Make Background Image Fitting to the UIView

  1. newme 2012/11/07 at 12:05 pm

    not work for me

  2. Munna Bhai 2013/09/05 at 6:25 pm

    use it in viewWillAppear . . .

  3. or 2014/05/04 at 6:34 pm

    Work Thank you !

Leave a Reply

Please log in using one of these methods to post your comment:

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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: