Having this code:
private let topView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.backgroundColor = UIColor(red: 216, green: 216, blue: 216)
return view
}()
private lazy var typeLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.textAlignment = .center
label.text = self.searchType == SearchType.why ? "Why" : "What"
label.font = UIFont.systemFont(ofSize: 28)
return label
}()
private func setupViews() {
self.view.addSubview(topView)
self.topView.addSubview(typeLabel)
self.view.addSubview(tableView)
self.topView.topAnchor.constraint(equalTo: self.view.topAnchor).isActive = true
self.topView.leadingAnchor.constraint(equalTo: self.view.leadingAnchor).isActive = true
self.topView.widthAnchor.constraint(equalTo: self.view.widthAnchor).isActive = true
self.topView.heightAnchor.constraint(equalTo: self.view.heightAnchor, multiplier: 1/8).isActive = true
self.typeLabel.topAnchor.constraint(equalTo: self.topView.topAnchor, constant: 20).isActive = true
self.typeLabel.leadingAnchor.constraint(equalTo: self.topView.leadingAnchor).isActive = true
self.typeLabel.widthAnchor.constraint(equalTo: self.topView.widthAnchor, multiplier: 1/4).isActive = true
}
private func borderLayer(position: CGPoint?, size: CGSize?) -> CALayer {
let borderLayer = CALayer()
borderLayer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
borderLayer.name = "Border"
borderLayer.backgroundColor = UIColor.red.cgColor
borderLayer.position = position == nil ? CGPoint.zero : position!
borderLayer.bounds.size = size == nil ? CGSize.zero : size!
borderLayer.borderWidth = 5
borderLayer.borderColor = UIColor.black.cgColor
borderLayer.shadowOpacity = 1.0
borderLayer.shadowOffset = CGSize(width: 20,height: 20)
return borderLayer
}
The problem is that the borderLayer
of my typeLabel
is not shown. The position and size are correct. I did the test putting the borderLayer
to topView
and it shows correctly, now the problem is when it is added to the daughter view of topView
. What am I doing wrong so that the layer is not shown?
Full code: link