Last active
February 27, 2017 21:58
-
-
Save ozgurshn/9727d714753ed7b55d21a7d3f97b69fc to your computer and use it in GitHub Desktop.
Live gradient rendering on XCode Storyboard with IBInspectable
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 CustomView: UIView { | |
@IBInspectable var gradient:Bool = false { | |
didSet { | |
if gradient | |
{ | |
let topColor = UIColor(red: 3/256, green: 51/256, blue: 75/256, alpha: 1.0) | |
let bottomColor = UIColor(red: 14/256, green: 149/256, blue: 217/256, alpha: 1.0) | |
let gradientBackgroundColors = [topColor.cgColor, bottomColor.cgColor] | |
let gradientLocations = [0.0,1.0] | |
let gradientLayer = CAGradientLayer() | |
gradientLayer.colors = gradientBackgroundColors | |
gradientLayer.locations = gradientLocations as [NSNumber] | |
gradientLayer.frame = self.bounds | |
self.layer.insertSublayer(gradientLayer, at: 0) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment