Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 5.1 : -[UIColor colorWithPatternImage:] background color draws solid black

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: Screenshots of issue

Has anybody else experienced this? Is there a workaround?

like image 984
iccir Avatar asked Mar 07 '12 21:03

iccir


1 Answers

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.

like image 114
iccir Avatar answered Nov 15 '22 17:11

iccir