I recently wrote an article on a simple custom
UIView class you can use to tile an image. Unfortunately – this doesn’t help us in a LaunchScreen, where custom classes are not allowed. Fortunately – there’s another way to tile an image, it’s pretty straightforward, and it doesn’t require a single line of code!
Step 1 – Bring in your image to tile into the Assets Catalog, then select Editor > Show Slicing.
Step 2 – The 1x, 2x and 3x options will disappear, and you will need to select Start Slicing.
Step 3 – You will have the option to slice horizontally, vertically or both:
Xcode will assume you want to slice the image in the center.
This will stretch the center part of your image, something like this:
This isn’t what you want!
Here are the defaults Xcode chose when I opted to slice my image: (you can find these in the Attributes Inspector for the image – and don’t forget, we’re still in the Assets Catalog)
Step 4 – We need to set the Left, Right, Top and Bottom to 0, and the Width and Height of the Tiles to the width and height of the image. Something like this:
Step 5 – Now, back in the Storyboard, we can add a
UIImageView, and in the Attributes Inspector, make sure Content Mode is set to Scale To Fill:
And there, like magic, the image in our image view will tile, and it works in the LaunchScreen storyboard too, hooray!