Skip to content

Instantly share code, notes, and snippets.

@mcz9mm
Last active November 28, 2016 14:43
Show Gist options
  • Save mcz9mm/3222ecf804a1d332d3b00005841cd24d to your computer and use it in GitHub Desktop.
Save mcz9mm/3222ecf804a1d332d3b00005841cd24d to your computer and use it in GitHub Desktop.
[Swift]UIViewのグラデーションをstoryBoard上で確認する ref: http://qiita.com/mcz9mm/items/0ac3634f91db2d40c240
@IBDesignable
class GradationView: UIView {
var gradientLayer: CAGradientLayer?
@IBInspectable var topColor: UIColor = UIColor.white {
didSet {
setGradation()
}
}
@IBInspectable var bottomColor: UIColor = UIColor.black {
didSet {
setGradation()
}
}
private func setGradation() {
gradientLayer?.removeFromSuperlayer()
gradientLayer = CAGradientLayer()
gradientLayer!.colors = [topColor.cgColor, bottomColor.cgColor]
gradientLayer!.frame.size = frame.size
layer.addSublayer(gradientLayer!)
layer.masksToBounds = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment