I have a custom UIControl
, and I want it to have a shadow, so I set the relevant properties on its layer
. A shadow appears around the view as desired, but a shadow also appears under the text of a UILabel
, which is a subview. How do you stop this? I only want the shadow around the outer superview.
...
init() {
label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
self.translatesAutoresizingMaskIntoConstraints = false
addSubview(label)
self.layer.masksToBounds = false
self.layer.shadowColor = UIColor.blackColor().CGColor
self.layer.shadowOpacity = 1.0
self.layer.shadowRadius = 2.0
// Adding these lines trying to explicitly stop shadow on label...
label.layer.shadowOpacity = 0
label.layer.shadowColor = nil
...
}