The new UIToolbar
object actively uses layout based on constraints, so it is better to override - (void)updateConstraints
method. To present custom views over UIToolbar
object it is better to subclass it and add custom container view:
- (UIView *)containerView
{
if (_containerView) {
return _containerView;
}
_containerView = [[UIView alloc] initWithFrame:self.bounds];
_containerView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
return _containerView;
}
Now you can safely add your custom views to the container view. To make the custom views responsive we need change the order of toolbar subviews after the constraints update:
- (void)updateConstraints
{
[super updateConstraints];
[self bringSubviewToFront:self.containerView];
}
Note, that if you are using UINavigationController
with custom toolbar, you should force it to update its layout before adding your custom subviews.
layoutSubviews
method of yourUIToolBar
and either bring your unresponsive views to the front or send the last view to the back inside of that override. – Photomechanical