While testing my application in today's release of iOS 5.1 GM, I noticed that some of my views are drawing solid black rather than their patterned background color. The exact same code works fine on previous iOS releases (tested on 4.2 - 5.0.1).
See screenshots:
Has anybody else experienced this? Is there a workaround?
Answering my own question (it took me a few days to debug this, so hopefully this saves somebody else some time ;) ):
The root cause involves using an patterned UIColor (via +[UIColor colorWithPatternImage:]
) as a background color on a UIView that is above a UIImageView with the same image.
Example:
UIImageView *imageView = [[UIImageView alloc] initWithImage:anImage];
[_containerView addSubview:imageView];
UIColor *patternColor = [UIColor colorWithPatternImage:anImage];
UIView *patternView = [[UIView alloc] initWithFrame:frame];
[patternView setBackgroundColor:patternColor];
[_containerView addSubview:patternView];
Both views draw black, and there appears to be a caching issue where all other uses of the image draws black until the application is suspended/resumed.
I filed issue #10795514 with Apple to report this, but it looks like it made it into 5.1. A reduction of this problem is available at: http://iccir.com/public/radar/Radar10795514.zip
The only workaround I found was to flatten the view hierarchy and draw the pattern image twice in the same view.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With