How does one make a navigation bar that fades out? the top having an alpha of say 0.5, with the bottom half being 0. As it goes from top to bottom, the alpha decreases and it becomes more transparent.
Something like this:
As you can see, it becomes more transparent as you go down the nav bar.
Try to use CAGradientLayer
for this purpose. I've tested and works.
For Swift 3.0.
let gradient: CAGradientLayer = CAGradientLayer()
// put colors into an array, from top to bottom
gradient.colors = [UIColor.black.withAlphaComponent(0.5).cgColor, UIColor.clear.cgColor]
gradient.frame = view.frame
// setting direction and stop points - from top to bottom
gradient.startPoint = CGPoint(x: 0, y: 0)
gradient.endPoint = CGPoint(x: 0, y: 0.5)
yourView.layer.insertSublayer(gradient, at: 0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With