I\'ve browsed around looking for an answer for this, but I\'ve only found people with similar problems and not this exact problem, so hopefully someone here can help me!
The correct approach is:
Use a normal toolbar with a normal height - do not set any constraint on the height.
Add leading constraint 0 to superview (not superview margin), trailing constraint 0 to superview (not superview margin).
Add top constraint 0 to top layout guide (or top of safe area). This will appear to leave 20 pixels of space above the toolbar, but laugh an evil laugh and proceed.
Set the view controller as the toolbar's delegate (there is a delegate outlet for this purpose).
Have the view controller adopt UIBarPositioningDelegate and implement the delegate method as follows:
class ViewController: UIViewController, UIBarPositioningDelegate {
func position(for bar: UIBarPositioning) -> UIBarPosition {
return .topAttached
}
}
This will cause the apparent height of the toolbar to be extended up behind the status bar when there is a status bar, but it will have normal height and be smack against the top when there is no status bar.
