Created
October 17, 2017 18:27
-
-
Save jonathanduty/430d83908de9fe95cf8f48aa0dc73db8 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
| import UIKit | |
| @IBDesignable class GradientView: UIView { | |
| @IBInspectable var topColor: UIColor = UIColor.white { | |
| didSet { | |
| setNeedsLayout() | |
| } | |
| } | |
| @IBInspectable var bottomColor: UIColor = UIColor.black { | |
| didSet { | |
| setNeedsLayout() | |
| } | |
| } | |
| @IBInspectable var shadowColor: UIColor = UIColor.black { | |
| didSet { | |
| setNeedsLayout() | |
| } | |
| } | |
| @IBInspectable var shadowX: CGFloat = 0 { | |
| didSet { | |
| setNeedsLayout() | |
| } | |
| } | |
| @IBInspectable var shadowY: CGFloat = -3 { | |
| didSet { | |
| setNeedsLayout() | |
| } | |
| } | |
| @IBInspectable var shadowBlur: CGFloat = 3 { | |
| didSet { | |
| setNeedsLayout() | |
| } | |
| } | |
| @IBInspectable var startPointX: CGFloat = 0 { | |
| didSet { | |
| setNeedsLayout() | |
| } | |
| } | |
| @IBInspectable var startPointY: CGFloat = 0 { | |
| didSet { | |
| setNeedsLayout() | |
| } | |
| } | |
| @IBInspectable var endPointX: CGFloat = 0 { | |
| didSet { | |
| setNeedsLayout() | |
| } | |
| } | |
| @IBInspectable var endPointY: CGFloat = 0 { | |
| didSet { | |
| setNeedsLayout() | |
| } | |
| } | |
| @IBInspectable var cornerRadius: CGFloat = 0 { | |
| didSet { | |
| setNeedsLayout() | |
| } | |
| } | |
| override class var layerClass: AnyClass { | |
| return CAGradientLayer.self | |
| } | |
| override func layoutSubviews() { | |
| let gradientLayer = layer as! CAGradientLayer | |
| gradientLayer.colors = [topColor.cgColor, bottomColor.cgColor] | |
| gradientLayer.startPoint = CGPoint(x: startPointX, y: startPointY) | |
| gradientLayer.endPoint = CGPoint(x: endPointX, y: endPointY) | |
| layer.cornerRadius = cornerRadius | |
| layer.shadowColor = shadowColor.cgColor | |
| layer.shadowOffset = CGSize(width: shadowX, height: shadowY) | |
| layer.shadowRadius = shadowBlur | |
| layer.shadowOpacity = 1 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment