Created
December 5, 2018 13:28
-
-
Save Kogarasi/ccaa6c204bb97d3d9308ae4c8a91b2fa to your computer and use it in GitHub Desktop.
GradientView in Swift
This file contains 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 | |
@IBInspectable var bottomColor: UIColor = UIColor.red | |
override class var layerClass: AnyClass { | |
return CAGradientLayer.self | |
} | |
override var layer: CAGradientLayer { | |
return super.layer as! CAGradientLayer | |
} | |
override func layoutSubviews() { | |
layer.colors = [topColor.cgColor, bottomColor.cgColor] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment