Kovu Kovu - 1 year ago 169
iOS Question

iOS UIView Background Image

I want to have a

as a background image on a

Here is my code:

UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"login.png"]];
self.view.backgroundColor = background;
[background release];

The Problem is, that the scale is not okay. It scaled 640 to 480, so I can't tell it 100% sure but it looks like only 300 to 250 is displayed or something like that.

Is there a fit to scale / fit to UIView / fit to size modus?

Answer Source

According to the UIColor API:

You can use pattern colors to set the fill or stroke color just as you would a solid color. During drawing, the image in the pattern color is tiled as necessary to cover the given area.

That means it tries to create a pattern out of your image to fill the area. I think the optimal way to do it is so rescale your image to fit exactly the UIView size.

There is a nice answer here how to resize your image during runtime:

The simplest way to resize an UIImage?

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download