I got the following code that I run in XCode playground:
let initalFrame = CGRect(x:0,y:0,width:10,height:10)
let myLabel = UILabel(frame: CGRectMake(0,0,50,50))
myLabel.backgroundColor = UIColor.greenColor().colorWithAlphaComponent(0.3);
myLabel.layer.borderColor = UIColor.darkGrayColor().CGColor
myLabel.layer.borderWidth = 2
myLabel.layer.cornerRadius = 15
myLabel.text = "Wow"
let gradient = CAGradientLayer()
gradient.frame = initalFrame
let startCol = UIColor(hue: 0.580555, saturation: 0.31, brightness: 0.90, alpha: 1.0)
let endCol = UIColor(hue: 0.58333, saturation: 0.5, brightness: 0.62, alpha: 1.0)
gradient.colors = [startCol, endCol]
myLabel.layer.insertSublayer(gradient, atIndex: 0)
myLabel.textAlignment = .Center
But I have faced the following issues:
An image here:1 How to fix my problems? Thanks for any hints. Does anyone look at this question!?
Since you're using a playground, play around with myLabel.clipSubviews
, myLabel.layer.masksToBounds
and the index at which you put the gradient layer