Top layout guide is deprecated in iOS 11
10,064
Solution 1
TopLayoutGuide is deprecated in iOS 11 so we have option to use SafeAreaLayoutGuide like this :
- First we can get view safeAreaLayoutGuide
let guide = view.safeAreaLayoutGuide
-
Second add constraint to guide
searchBackView.topAnchor.constraint(equalTo: guide.topAnchor).isActive = true
Solution 2
The Obj-C version:
[[searchBackView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor constant:0] setActive:YES];
If you have translucent bars note: then the topLayoutGuide is below the bar, e.g the statusBar.
see: topLayoutGuide It explains conditions which is important to consider.
Whereas the safeAreaLayoutGuide.topAnchor would not be beneath the NavigationBars; much simpler to work with.
Author by
Sukhpreet
Updated on June 07, 2022Comments
-
Sukhpreet about 2 years
Since
topLayoutGuide
property is now deprecated in iOS 11, what is alternative to use top layout guide?backView.topAnchor.constraint(equalTo: topLayoutGuide.bottomAnchor)
-
Mozahler over 6 years@UdayBabariya - yes, there is a typo in this answer. "guide.bottomAnchor" should be "guide.topAnchor". Give it a try - fixed it for me.
-
Roger Perez over 5 yearsWhat would be the equivalent in Obj- c?