UIKit: UIToolbar doesn't display custom shadows

Originator:adrian.kashivskyy
Number:rdar://14177981 Date Originated:17-Jun-2013 09:40 PM
Status:Closed Resolved:Yes
Product:iOS SDK Product Version:iOS 7.0 Beta 2 (11A4400f)
Classification:Serious Bug Reproducible:Always
 
Summary:

I am experiencing an issue with the new UIToolbar. 

Steps to Reproduce:

1. Create a simple UINavigationController with a simple root UIViewController and set it as the window's root view controller.
2. In your UIViewController's -viewWillAppear set some toolbar items: self.toolbarItems = @[ /* any UIBarButtonItem */ ];
3. Then (still in -viewWillAppear:) set a custom background image for your toolbar

Expected Results:

A UIToolbar with custom background image and a custom shadow image on top of it (like in iOS 6)

Actual Results:

Although UIToolbar displays a custom background, it ignores the shadow I specified and displays the default 0.5pt line.

This is the UIToolbar actual view hierarchy (printed by -recursiveDescription):

<UIToolbar: 0x9d9af40; frame = (0 524; 320 44); opaque = NO; autoresize = W+TM; layer = <CALayer: 0x9d7a720>>
   | <_UIToolbarBackground: 0x9d7e000; frame = (0 0; 320 44); autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x9d9a9c0>> - (null)
   | <UIView: 0x9d9d360; frame = (0 -0.5; 320 0.5); autoresize = W+BM; layer = <CALayer: 0x9d82950>>
   | <UIToolbarButton: 0x9da2d10; frame = (16 0; 23 44); opaque = NO; layer = <CALayer: 0x9da2880>>
   |    | <_UIToolbarNavigationButton: 0x9da3680; frame = (0 0; 45 30); opaque = NO; layer = <CALayer: 0x9da3610>>
   |    |    | <UIImageView: 0x9d7de50; frame = (11 3; 23 23); clipsToBounds = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x9d7dee0>> - (null)
   |    |    | <UIButtonLabel: 0x9da3ee0; frame = (0 0; 0 0); clipsToBounds = YES; hidden = YES; opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x9da3fd0>>

Notice the UIView (0x9d9d360) which is the 0.5pt (1px on Retina display) line drawn on top of UIToolbar. Additionally, there is no sign of UIImageView which would hold the shadow image.

Regression:

This is a serious SDK bug and should be fixed ASAP.

Notes:

The code I'm using:

[self.navigationController.toolbar setBackgroundImage:[[UIImage imageNamed:@"UIToolbarShadowImage.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0) resizingMode:UIImageResizingModeStretch] forToolbarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];

[self.navigationController.toolbar setShadowImage:[[UIImage imageNamed:@"UIToolbarBackgroundImage.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(2, 0, 1, 0) resizingMode:UIImageResizingModeStretch forToolbarPosition:UIBarPositionAny];

--- 17-Jun-2013 09:43 PM

Steps to Reproduce:

1. Create a simple UINavigationController with a simple root UIViewController and set it as the window's root view controller.
2. In your UIViewController's -viewWillAppear set some toolbar items: self.toolbarItems = @[ /* any UIBarButtonItem */ ];
3. In that method: self.navigationController.toolbarHidden = NO;
4. Then (still in -viewWillAppear:) set a custom background image for your toolbar
6. Still in that method, set a custom shadow image using -setShadowImage:forToolbarPosition:
7. Put a breakpoint at the end of the method (just to do (lldb) [[[self navigationController] toolbar] recursiveDescription])

--- 18-Jun-2013 01:14 AM / ADR

Engineering has requested a test case/sample app in order to further investigate this issue.

--- 19-Jun-2013 06:51 PM

Attaching a demo project, as you requested.

--- 19-Jun-2013 06:51 PM

'ToolbarDemo.zip' was successfully uploaded

--- 26-Jun-2013 02:48 AM / ADR

Engineering has requested the following information in order to further investigate this issue:

Does this issue also occur with iOS 7 beta 2 (11A4400f)? Please verify with this release, and update your bug report with the results.

--- 04-Jul-2013 12:39 PM

Yes, the issue is present in iOS 7 Beta 2 (11A4400f).

--- 29-Jul-2013 09:45 PM

iOS 7 Beta 4 (11A4435d) almost fixed the issue. A UIImage is properly added to UIToolbar's hierarchy and is properly displayed, but strangely it has a background color.

After some debugging, I found out that the backgroundColor property of UIImageView containing the shadow image is set to `UIDeviceRGBColorSpace 0 0 0 0.3`:

(lldb) expr (UIToolbar *)[[self navigationController] toolbar]
(UIToolbar *) $2 = 0x089946c0
(lldb) po [$2 recursiveDescription]
<UIToolbar: 0x89946c0; frame = (0 524; 320 44); opaque = NO; autoresize = W+TM; layer = <CALayer: 0x8994800>>
   | <_UIToolbarBackground: 0x8995a10; frame = (0 0; 320 44); opaque = NO; autoresize = W; userInteractionEnabled = NO; layer = <CALayer: 0x8995b10>> - (null)
   | <UIImageView: 0x8997230; frame = (0 -3; 320 3); opaque = NO; autoresize = W+BM; userInteractionEnabled = NO; layer = <CALayer: 0x8997200>> - (null)
   | <UIToolbarButton: 0x89981e0; frame = (16 0; 23 44); opaque = NO; layer = <CALayer: 0x8998330>>
   |    | <_UIToolbarNavigationButton: 0x8998600; frame = (0 0; 45 30); opaque = NO; layer = <CALayer: 0x8998780>>
(lldb) po 0x8997230
<UIImageView: 0x8997230; frame = (0 -3; 320 3); opaque = NO; autoresize = W+BM; userInteractionEnabled = NO; layer = <CALayer: 0x8997200>> - (null)
(lldb) po [0x8997230 backgroundColor]
UIDeviceRGBColorSpace 0 0 0 0.3

--- 01-Aug-2013 01:03 AM / ADR

This bug has been closed as Duplicate. 14374501

--- 13-Aug-2013 01:54 PM

The problem 14374501 appears to be closed, but the issue is STILL present in iOS Simulator with iOS 7.0 Beta 5 11A4449b  (check out my attached demo project).

--- 20-Nov-2013 03:12 AM / ADR

Engineering has requested the following information in order to further investigate this issue:

Does this issue also occur with iOS 7.1 beta? Please verify with this release, and update your report with the results.

--- 21-Nov-2013 09:47 PM

The issue seems to be fixed in iOS 7.1 Beta (11D5099e).

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!