Skip to content

Instantly share code, notes, and snippets.

@muhlenXi
Created March 8, 2019 09:09
Show Gist options
  • Save muhlenXi/206cba25a2d56a3642d2919b5903e592 to your computer and use it in GitHub Desktop.
Save muhlenXi/206cba25a2d56a3642d2919b5903e592 to your computer and use it in GitHub Desktop.
给视图添加渐变效果
let contentView = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: 200))
let gradientLayer = CAGradientLayer()
gradientLayer.frame = self.bounds
gradientLayer.colors = [UIColor.white.withAlphaComponent(0).cgColor, UIColor.white.cgColor]
gradientLayer.startPoint = CGPoint(x: 0, y: 0)
gradientLayer.endPoint = CGPoint(x: 0, y: 0.5)
contentView.layer.addSublayer(gradientLayer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment