Created
June 20, 2019 00:20
-
-
Save dillon-mce/bb4293cac35142342c66a2102a9c3a3f to your computer and use it in GitHub Desktop.
A Simple Gradient View Snippet
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
import UIKit | |
class GradientView: UIView { | |
override class var layerClass: AnyClass { | |
return CAGradientLayer.self | |
} | |
override init(frame: CGRect) { | |
super.init(frame: frame) | |
setupGradient() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
super.init(coder: aDecoder) | |
setupGradient() | |
} | |
var gradientLayer: CAGradientLayer { | |
return layer as! CAGradientLayer | |
} | |
func setupGradient(startColor: UIColor = .white, | |
endColor: UIColor = .black, | |
startPoint: CGPoint = CGPoint(x: 0.5, y: 0.0), | |
endPoint: CGPoint = CGPoint(x: 0.5, y: 1.0)) { | |
backgroundColor = .clear | |
gradientLayer.colors = [startColor.cgColor, endColor.cgColor] | |
gradientLayer.startPoint = startPoint | |
gradientLayer.endPoint = endPoint | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment