Reputation: 10764
Setup:
I have a View Controller that consists of a View
and a Container View
.
I have setup the View
and the Container View
using class sizes.
The code below adds the gradient just fine:
class ViewController: UIViewController {
@IBOutlet weak var graphView: UIView!
@IBOutlet weak var containerView: UIView!
let backgroundColor = CAGradientLayer().graphViewBackgroundColor()
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
backgroundColor.frame = self.graphView.bounds
self.graphView.layer.addSublayer(backgroundColor)
}
}
Output:
There are no constraints laid out in code.
Problem:
However, I do have a label with black background that is not appearing. If I comment out the following lines, the label appears:
//backgroundColor.frame = self.graphView.bounds
//self.graphView.layer.addSublayer(backgroundColor)
Output:
Question:
Why is the gradient hiding the UILabel element that is in Auto-layout?
Upvotes: 0
Views: 117
Reputation: 1534
Have you tried bringing the label to the front?
graphView.bringSubviewToFront(label)
Upvotes: 1