Skip to content

Instantly share code, notes, and snippets.

@rinat-enikeev
Created June 10, 2015 11:58
Show Gist options
  • Save rinat-enikeev/f96ccfeb8dfd660212a5 to your computer and use it in GitHub Desktop.
Save rinat-enikeev/f96ccfeb8dfd660212a5 to your computer and use it in GitHub Desktop.
func drawHorizontalGradient(over container : UIView, left leftColor: UIColor, right rightColor: UIColor) {
let maskLayer = CAGradientLayer()
maskLayer.colors = [leftColor.CGColor, rightColor.CGColor]
maskLayer.startPoint = CGPointMake(0.0, 0.5)
maskLayer.endPoint = CGPointMake(1.0, 0.5)
maskLayer.bounds = container.bounds
maskLayer.anchorPoint = CGPointZero
container.layer.insertSublayer(maskLayer, atIndex: 0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment