Here is what I am trying to do:
The screenshot is taken from Iphone:
This is my code:
import UIKit
class GradientController: UIViewController {
@IBOutlet weak var viewBottomBorder: UIView!
lazy var gradient: CAGradientLayer = {
let gradient = CAGradientLayer()
gradient.type = .axial
gradient.colors = [UIColor.clear.cgColor,UIColor.black.cgColor]
gradient.locations = [0, 1]
return gradient
}()
override func viewDidLoad() {
super.viewDidLoad()
gradient.frame = view.bounds
viewBottomBorder.layer.addSublayer(gradient)
}
}
Question: How to show same bottom gradient colour the view?
Can someone please explain to me how to solve this? I’ve tried to solve this issue but no results yet.
2
Answers
You can save yourself a lot of work and extra code by using a
UIView
subclass such as this:Now, in Storyboard, set the Custom Class of your
viewBottomBorder
toGradientView
, and your controller code becomes:try using this code it will work for you also you can change start and end points as per requirements.
Attaching image for reference.