I want to repeat the following image:
to achieve the following background:
I tried a few codes as follow:
bluePatternView.backgroundColor = [UIColor colorWithPatternImage:
[[UIImage imageNamed:@"blue_pattern.png"] stretchableImageWithLeftCapWidth:0 topCapHeight:0]];
and:
bluePatternView.backgroundColor =
[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"blue_pattern.png"]];
I also tried to draw image with CGContextDrawTiledImage with no success.
How that can be done?!
EDIT: result of implementing luk2302. please give him recognition by upvoting
bluePatternView.backgroundColor =
[UIColor colorWithPatternImage:[UIImage imageNamed:@"blue_pattern.png"]];
result:
Background-repeat: This property is used to repeat the background image both horizontally and vertically.
You can repeat your image horizontally by using background-repeat:repeat-x . This text is displayed in front of the repeating image. That's because it's a background image, as opposed to a normal image that has been defined using normal image code.
I found solution in images.xcassets,
Step 1:- Put your image to images.xcassets
Step 2:- Click on image, then click on bottom right corner written “Show Slicing”
Step 3:- Click on Start Slicing
Step 4:- Click on "Slice Horizontally and Vertically" button
Step 5:- Here you will see 3-Horizontal and 3-Vertical slice lines.
Step 6:- Use this image.
And now image will be repeated.
Note:- If you give slicing to 2x image it will repeat just 2x image, for 3x images you need to do the same slicing.
Example by Apple
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With