I need to make this background in all my view controllers.

enter image description here

When working with android, I collected such an xml file

<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" android:thickness="0dp"> <gradient android:angle="180" android:endColor="@color/ntz_background_grey" android:centerColor="@color/ntz_background_light_grey" android:startColor="@color/ntz_background_grey" android:type="linear" /> </shape> 

In which he described customization, which color at the beginning, which at the middle and at the end, such a background was obtained.

How to make it in Xcode? I found only a few answers where it was explained how to put a picture on the background, but it seems to me that there must be a way of customization.

Or how does it work in Xcode?

    1 answer 1

    Well, in general, it all comes down to a picture on the background. But you can do whatever you want in the code, first a gradient, and then set it as the background color. One of the options:

     func createGradientBackground() { let gradientLayer = CAGradientLayer() gradientLayer.frame = self.view.bounds gradientLayer.colors = [UIColor.darkGray.cgColor, UIColor.lightGray.cgColor, UIColor.darkGray.cgColor] gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.5) gradientLayer.endPoint = CGPoint(x: 1.0, y: 0.5) UIGraphicsBeginImageContext(gradientLayer.bounds.size) gradientLayer.render(in: UIGraphicsGetCurrentContext()!) let image = UIGraphicsGetImageFromCurrentImageContext() UIGraphicsEndImageContext() self.view.backgroundColor = UIColor(patternImage: image!) } 

    Well, the result:

    enter image description here