Created
June 30, 2018 02:41
-
-
Save tuppaware/47b081241e9beb2d9d48476a9221dbbd to your computer and use it in GitHub Desktop.
Add Pride colours to any UIView with this Swift extension
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
extension UIView { | |
func prideColors(){ | |
// Offical colors | |
let colors = [UIColor(red:0.91, green:0.00, blue:0.00, alpha:1.0),UIColor(red:1.00, green:0.55, blue:0.00, alpha:1.0), UIColor(red:1.00, green:0.94, blue:0.00, alpha:1.0),UIColor(red:0.00, green:0.51, blue:0.12, alpha:1.0),UIColor(red:0.00, green:0.27, blue:1.00, alpha:1.0),UIColor(red:0.46, green:0.00, blue:0.54, alpha:1.0)] | |
for (index,color) in colors.enumerated() { | |
let gradient = CAGradientLayer() | |
gradient.frame = CGRect(x: (Int(self.bounds.width)/6)*index, y: 0, width: Int(self.bounds.width), height: Int(self.bounds.height)) | |
gradient.colors = [color.cgColor, color.cgColor] | |
self.layer.addSublayer(gradient) | |
} | |
} | |
} | |
// to call simply go | |
myView.prideColors() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment