SUDHAKAR RAYAPUDI
SUDHAKAR RAYAPUDI

Reputation: 551

iOS Background Image is repeated in iPad?

I've got an image with 1x , 2x and 3x types with resolutions 404*750 , 808*1500 and 1212*2250 respectively.

Here is my code:

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

On my iPhone the background is not repeated and its good. but the iPad background is repeated 4 times.

Would you know why is this happening?

Upvotes: 4

Views: 591

Answers (2)

Rohit Kumar
Rohit Kumar

Reputation: 887

iOS will pick the image itself if you just follow the naming convention.

1x: my_image.png
2x: [email protected]
3x: [email protected]
1x iPad: my_image~ipad.png
2x iPad: [email protected]

Upvotes: 2

Mihir Mehta
Mihir Mehta

Reputation: 13833

From Apple's reference

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.

So in iphone device image is large enough to cover the area ... but in ipad it's not large enough to cover the area ... so it will repeat itself.

You can use image.xcassets for different image for iphone and iPad ...

see the screen shot

enter image description here

You can use different image for iPad with proper size to overcome this error

Upvotes: 5

Related Questions