JackTurky JackTurky - 1 year ago 58
Objective-C Question

How to fill background image of an UIView

I have an

and I set a background image in this way:

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

My problem is that back-image is not centered inside the view, but it's replayed some times to fill all the view. Is there a way to center image inside uiview and scretch to have screen size?

Note: I can't use
for background cause I have a

Answer Source

You need to process the image beforehand, to make a centered and stretched image. Try this:

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

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