Last active
November 28, 2016 14:43
-
-
Save mcz9mm/3222ecf804a1d332d3b00005841cd24d to your computer and use it in GitHub Desktop.
[Swift]UIViewのグラデーションをstoryBoard上で確認する ref: http://qiita.com/mcz9mm/items/0ac3634f91db2d40c240
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
@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