Setting gradient background color to LaunchScreen which will display a logo image at center

Roopesh85 picture Roopesh85 · Mar 23, 2016 · Viewed 9.7k times · Source

I have a requirement to set a Gradient background to the launch screen with a UIImageView in the center which shows the app logo . I tried having a view controller but I realised code will never be invoked.

I need some way to get behaviour as the code below does

self.view.backgroundColor = UIColor(patternImage: UIImage(named: "background.png")!)

I went through lot of answers about the same topic, most of the questions on gradient colour don't seem to have any additional requirements like showing another image other than the background .

I can hardcode the color in IB but i don't get the gradient.

Answer

wottle picture wottle · Mar 23, 2016

You cannot run code or use any custom classes in the Launch Screen. Basically the launch screen can use an interface builder file and accommodate size classes / auto layout, but you cannot create a gradient in code like you have.

You'll have to supply a stretchable image, which contains enough data for it to be viable in all resolutions.