Created
February 12, 2016 18:00
-
-
Save mingsai/6ebd4c72a8258d00835d to your computer and use it in GitHub Desktop.
A Swift extension for configuring a background gradient color when given a set of ColorRefs.
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
| // | |
| // MNGLayerExtensions.swift | |
| // | |
| // | |
| // Created by Tommie N. Carter, Jr., MBA on 6/21/15. | |
| // Copyright © 2015 MING Technology. All rights reserved. | |
| // | |
| import QuartzCore | |
| extension CALayer { | |
| func configureGradientBackground(colors:CGColorRef...){ | |
| let gradient = CAGradientLayer() | |
| let maxWidth = max(self.bounds.size.height,self.bounds.size.width) | |
| let squareFrame = CGRect(origin: self.bounds.origin, size: CGSizeMake(maxWidth, maxWidth)) | |
| gradient.frame = squareFrame | |
| gradient.colors = colors | |
| self.insertSublayer(gradient, atIndex: 0) | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment