Fill background Image of a UIView

suggest change

image.png must be in the app bundle. imageNamed: returns nil when it is missing, and the pattern is then empty. UIGraphicsBeginImageContext uses a scale of 1, so the result is blurry on a Retina screen; UIGraphicsBeginImageContextWithOptions with scale 0 uses the screen scale.

Objective-C

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0);
[[UIImage imageNamed:@"image.png"] drawInRect:self.view.bounds];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
self.view.backgroundColor = [UIColor colorWithPatternImage:image];

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents