最佳答案
为此尝试使用 CAGradientLayer
。我已经测试过并且可以工作。
对于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)
关于ios - 如何制作褪色的导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39930846/