How to fix UIToolbar Auto Layout issues

Issue #538

Hierarchy

1
UIToolbar -> _UIToolbarContentView -> _UIButtonBarStackVie

UIToolbarContentView

1
2
_UIToolbarContentView's width should equal 0
_UIToolbarContentView's height should equal 0

Workaround that fixes 1 warning

1
2
toolbar.setItems(items, animated: false)
toolbar.updateConstraintsIfNeeded()

###

Set frame explicitly

Use a non .zero frame that is close to the view bounds width

1
2
3
4
let toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: 375, height: 30))
DispatchQueue.main.async {
self.toolbar.updateConstraintsIfNeeded()
}

Comments