Skip to content

Instantly share code, notes, and snippets.

@ozgurshn
Last active February 27, 2017 21:58
Show Gist options
  • Save ozgurshn/9727d714753ed7b55d21a7d3f97b69fc to your computer and use it in GitHub Desktop.
Save ozgurshn/9727d714753ed7b55d21a7d3f97b69fc to your computer and use it in GitHub Desktop.
Live gradient rendering on XCode Storyboard with IBInspectable
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