在视图中实现渐变颜色后标签未显示 xcode
label not showing after implement gradient color at view xcode
实施此渐变后我的标签不显示
gradientLayer = CAGradientLayer()
gradientLayer.frame = self.myview.bounds
gradientLayer.colors = [UIColor.init(displayP3Red:0.04, green:0.47, blue:0.74, alpha:1.0).cgColor, UIColor.init(displayP3Red:0.00 ,green:0.80, blue:0.67 ,alpha:1.0).cgColor]
self.myview.layer.addSublayer(gradientLayer)
下面的代码显示 UILabel
和 CAGradientLayer
,
override func viewDidLoad() {
super.viewDidLoad()
let GradientLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
GradientLabel.center = CGPoint(x: 160, y: 285)
self.view.addSubview(GradientLabel)
let gradientLayer = CAGradientLayer()
gradientLayer.frame = GradientLabel.bounds
gradientLayer.colors = [UIColor.init(displayP3Red:0.04, green:0.47, blue:0.74, alpha:1.0).cgColor, UIColor.init(displayP3Red:0.00 ,green:0.80, blue:0.67 ,alpha:1.0).cgColor]
GradientLabel.layer.addSublayer(gradientLayer)
}
实施此渐变后我的标签不显示
gradientLayer = CAGradientLayer()
gradientLayer.frame = self.myview.bounds
gradientLayer.colors = [UIColor.init(displayP3Red:0.04, green:0.47, blue:0.74, alpha:1.0).cgColor, UIColor.init(displayP3Red:0.00 ,green:0.80, blue:0.67 ,alpha:1.0).cgColor]
self.myview.layer.addSublayer(gradientLayer)
下面的代码显示 UILabel
和 CAGradientLayer
,
override func viewDidLoad() {
super.viewDidLoad()
let GradientLabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 21))
GradientLabel.center = CGPoint(x: 160, y: 285)
self.view.addSubview(GradientLabel)
let gradientLayer = CAGradientLayer()
gradientLayer.frame = GradientLabel.bounds
gradientLayer.colors = [UIColor.init(displayP3Red:0.04, green:0.47, blue:0.74, alpha:1.0).cgColor, UIColor.init(displayP3Red:0.00 ,green:0.80, blue:0.67 ,alpha:1.0).cgColor]
GradientLabel.layer.addSublayer(gradientLayer)
}