Reputation: 137
let bottomBorder = CALayer()
bottomBorder.backgroundColor = UIColor.viewShadowGray().cgColor
bottomBorder.frame = CGRect(x: 0, y: view.frame.size.height - 1, width: view.frame.size.width, height: 1)
view.layer.addSublayer(bottomBorder)
How to modify this to add gradient to it such that it looks like this:
Upvotes: 1
Views: 540
Reputation: 23078
Use a CAGradientLayer
:
let gradientLayer = CAGradientLayer()
gradientLayer.frame = CGRect(x: 0, y: view.frame.size.height - 1, width: view.frame.size.width, height: 1)
gradientLayer.colors = [
UIColor.white.withAlphaComponent(0.5).cgColor,
UIColor.white.withAlphaComponent(0.0).cgColor
]
view.layer.addSublayer(gradientLayer)
Adjust the gradients colors to you needs.
Upvotes: 2