UIToolbar at top of screen + safe area

I'm using a UIToolbar across the top of my app.


When I constrain it to the safe area I get a black band at the top of the screen. So I set the background to the same color, but then I get a thin line at the top of the toolbar. How can I resolve this without the thin border around the toolbar? Is there a clean way to do it? Should I use a UIView instead of UIToolbar? Can I get this UI out of a UINavigationBar? What do Pages/Keynote/Numbers use for their toolbars?


When I move the toolbar to the bottom of the safe area, it is somehow smart and draws its color all the way to the bottom of the superview. It seems UIToolbar is meant to live at the bottom of the screen.


thanks!

Answered by Audulus in 338083022

Simply setting Clips To Bounds on the UIToolbar got rid of the border.

Set your view controller as the toolbar‘s delegate, and implement the delegate method positionForBar to return top attached.


Disclaimer: I haven’t tried this recently. But that’s been the official way to do it for a while I think.

Thanks junkpile. Alas that moves the line to the bottom of the UIToolbar, which doesn't satisfy the design.

Accepted Answer

Simply setting Clips To Bounds on the UIToolbar got rid of the border.

That sounds a bit hackish (could break something else in a future iOS release or on a different device or toolbar position). A better way to hide the line might be to call setShadowImage on the toolbar using an empty or transparent image.

Could you post this piece of code ?

UIToolbar at top of screen + safe area
 
 
Q