Missing shadow (hairline) on iOS7 UIToolbar
Asked Answered
T

2

9

In iOS7, UIToolbar does not appear to have a little line (the shadow) on the top or bottom borders, which makes it difficult to distinguish from the rest of the app. How can I restore the shadow at the bottom of the toolbar when it is at the top of the screen?

EDIT: I should clarify that my toolbar is positioned at the top of the screen. After moving things around I realized that it IS drawing a shadow, but it's on the top, and therefore off-screen. What I want is for the shadow to appear at the bottom like a UINavigationBar.

Tical answered 18/12, 2013 at 23:1 Comment(3)
Did you try setting a shadow no the CALayer backing the UIToolbar?Ponce
Ah...one thought...it's probably just drawing the shadow off the top of the toolbar off-screen. I want a shadow on the bottom, like UINavigationBar.Tical
@Tical You need to implement the toolbar's delegate. See my answer.Hagerty
S
22

This is because, by default, toolbars are attached to bottom, so the shadow line appears at the top (if they are at the bottom). You need to set the delegate of the toolbar and implement the following UIBarPositioningDelegate method like so:

- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar
{
    return UIBarPositionTop; //or UIBarPositionTopAttached
}
Submission answered 18/12, 2013 at 23:11 Comment(1)
That does it. Seems like it should just be a property you can set. Thanks for the help.Tical
T
2

I just ran into a case where a view was positioned between a top and bottom toolbar and configured to auto-resize to fill the space. However, it was layered above the bottom toolbar and the auto-resize made it cover the bottom toolbar's top shadow. The solution was to adjust the layering in Interface Builder so the toolbars were layered above the other views.

Taub answered 7/10, 2015 at 22:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.