Created
October 31, 2019 10:23
-
-
Save iSapozhnik/7534b7e7d05df3f22f0b29bc870cea62 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GradientView: UIView { | |
var gradientLayer: CAGradientLayer! | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
commonInit() | |
} | |
required init?(coder: NSCoder) { | |
super.init(coder: coder) | |
commonInit() | |
} | |
private func commonInit() { | |
gradientLayer = CAGradientLayer() | |
gradientLayer.frame = bounds | |
gradientLayer.colors = [UIColor(red:0.29, green:0.23, blue:0.54, alpha:1.0).cgColor, UIColor(red:0.50, green:0.35, blue:0.74, alpha:1.0).cgColor, UIColor(red:0.64, green:0.63, blue:0.66, alpha:1.0).cgColor] | |
gradientLayer.colors = [UIColor.red.cgColor, UIColor.yellow.cgColor] | |
gradientLayer.startPoint = CGPoint(x: 0.0, y: 0.5) | |
gradientLayer.endPoint = CGPoint(x: 1.2, y: 1.0) | |
layer.insertSublayer(gradientLayer, at: 0) | |
} | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
gradientLayer.frame = bounds | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment