Skip to content

Instantly share code, notes, and snippets.

@Kogarasi
Created December 5, 2018 13:28
Show Gist options
  • Save Kogarasi/ccaa6c204bb97d3d9308ae4c8a91b2fa to your computer and use it in GitHub Desktop.
Save Kogarasi/ccaa6c204bb97d3d9308ae4c8a91b2fa to your computer and use it in GitHub Desktop.
GradientView in Swift
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