Swift Gradient in 4 lines of code

Swift Gradient in 4 lines of code

Line 2 sets the frame size of your gradientLayer to match the size of the view you are adding the gradient to. Here, all we are doing is adding a sublayer to the current view and setting that sublayer to the gradientLayer we have been setting up in lines 1–3. Turns out, my gradientLayer was being added on top of all the content I had on that app screen and the fix was in line at: 0)Adding the at: 0 to the insertSublayer function tells Swift to set that sublayer at index 0 of the view.

Source: medium.com