I'm completely new to UILayoutGuide. I'd like to position a UILabel in the middle of the white space below the imageView, which is the superview of both imageView and UILabel (see view hierarchy below).
Normally, I would add another view and set top constraint to UIImageView and bottom constraint to the bottom edge, then center the label both horizonally and vertically to the view.
But I decided to achieve it using UILayoutGuide. Here is my code:
override func awakeFromNib() {
super.awakeFromNib()
let topGuide = UILayoutGuide()
let bottomGuide = UILayoutGuide()
self.view.addLayoutGuide(topGuide)
self.view.addLayoutGuide(bottomGuide)
topGuide.bottomAnchor.constraint(equalTo: title.topAnchor).isActive = true
bottomGuide.topAnchor.constraint(equalTo: title.bottomAnchor).isActive = true
self.view.layoutIfNeeded()
}
The result is that my UILabel does not show at all. What am I doing wrong?