1
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: enter image description here

Doj Yias Lem
  • 137
  • 8
  • Look here: https://stackoverflow.com/questions/30876811/set-calayer-gradient-background – JonJ Sep 18 '18 at 06:47
  • You are looking for `CAGradientLayer`, a subclass of `CALayer` done for that. Also, that depending on your final goal, that gradient could be interpreted as a inner/outer shadow and be done without `CAGradientLayer`. – Larme Sep 18 '18 at 08:17
  • Possible duplicate of [How to Apply Gradient to background view of iOS Swift App](https://stackoverflow.com/questions/24380535/how-to-apply-gradient-to-background-view-of-ios-swift-app) – Matias Jurfest Sep 18 '18 at 10:10

1 Answers1

2

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.

zisoft
  • 22,770
  • 10
  • 62
  • 73