我得到了以下在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
但我遇到了以下问题:
此处的图片:1 如何解决我的问题?谢谢你的任何提示。有人看过这个问题吗??
答案 0 :(得分:0)
由于您正在使用游乐场,请使用myLabel.clipSubviews
,myLabel.layer.masksToBounds
以及放置渐变图层的索引