Skip to content

Instantly share code, notes, and snippets.

@novinfard
Last active February 4, 2019 16:12
Show Gist options
  • Save novinfard/ace34965043f2a6e3e91507b98caca35 to your computer and use it in GitHub Desktop.
Save novinfard/ace34965043f2a6e3e91507b98caca35 to your computer and use it in GitHub Desktop.
[Add gradient layer to view]
private let gradientLayer = CAGradientLayer()
override func layoutSubviews() {
super.layoutSubviews()
super.layoutIfNeeded()
if let viewBounds = self.gradientView?.bounds {
self.gradientLayer.frame = viewBounds
}
}
private func addGradientBackground() {
self.gradientView?.addGradientMask(
gradientLayer: self.gradientLayer,
colours: [UIColor.clear.cgColor, UIColor.white.cgColor],
isVertical: true
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment