IOS 5.1: - background color [UIColor colorWithPatternImage:] - black

While testing my application in today's release of iOS 5.1 GM, I noticed that some of my views paint a solid black color rather than their patterned background color. The exact same code works fine in previous versions of iOS (tested on 4.2 - 5.0.1).

See screenshots: Screenshots of issue

Has anyone else experienced this? Is there any workaround?

+8
ios objective-c iphone uicolor
source share
2 answers

Answering my own question (it took me a few days to debug this, so hopefully it will save some time;)):

The main reason is to use the UIColor template (via +[UIColor colorWithPatternImage:] ) as the background on the UIView, which is located above the 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 are painted in black, and there seems to be a caching issue in which all other uses of the image are black until the application is paused / resumed.

I registered issue number 10795514 with Apple to report this, but it looks like it has turned into 5.1. An abbreviation for this problem can be obtained at: http://iccir.com/public/radar/Radar10795514.zip

The only workaround I found was to flatten the view hierarchy and double-draw the template image in the same view.

+12
source share

I had a problem with iOS 5.1 on the iPad where I used colorWithPatternImage in a UIScrollView, for example:

 scrollView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"YOURIMAGE.jpg"]]; 

This works in iOS 6 (e.g. iPad2 and later), however, on the original iPad, where you can upgrade iOS to 5.1.1, it will show a white or other solid color that you have defined somewhere. The fix is ​​to use a slightly less attractive method in which you set the backgroundView scrollview as follows:

 scrollView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YOURIMAGE.png"]]; 

I tested this on iOS 6 and iOS 5.1, so it should also apply to the iPhone if you have problems with it.

0
source share

All Articles