Created
May 24, 2020 04:02
-
-
Save nitin-agam/acea831a3a22fceb751b49198cc11a21 to your computer and use it in GitHub Desktop.
This file contains 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 { | |
class func gradientViewWithText(text: String, size: CGSize, firstColor: UIColor, secondColor: UIColor, font: UIFont) -> UIView { | |
let view = UIView() | |
let layer = CAGradientLayer() | |
layer.colors = [firstColor.cgColor, secondColor.cgColor] | |
layer.frame = CGRect(x: 0, y: 0, width: size.width, height: size.height) | |
view.layer.addSublayer(layer) | |
let textLabel = UILabel() | |
textLabel.font = font | |
textLabel.textAlignment = .center | |
textLabel.text = text | |
textLabel.frame = layer.frame | |
view.addSubview(textLabel) | |
view.mask = textLabel | |
return view | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment