views:

467

answers:

1

Good day all;

I am not sure what has changed to prevent this from working. On iOS 3 SDK, the following code worked fine in a CATiledLayer class:

- (void)drawInContext:(CGContextRef)context {
    UIImage* image = [[ResourcesManager sharedResourcesManager] getUIImageFromArray:Image_Cell_Background Index:[mazeCell zone]];
    UIColor* color = [[UIColor alloc] initWithPatternImage:image];

    [self setBackgroundColor:[color CGColor]];
    [color release];    

However, compiling for iOS 4 and executing on simulator fails to render the image. I am baffled especially since images added as sublayers render just fine. Only the background doesn't render.

+1  A: 

OK after spending a few days on this I have come up with a work-around.

Firstly, I tried doing this in a UIView and still had the same issues. I then tried other types of GUI components that have a backgroundColor property.

They all produced the same issue. From what I can tell, this appears to be a bug and something to do with the new image loading / caching process implemented that interprets whether or not to use HD or SD graphics.

Basically, the workaround it to load the background image as subview or sublayer (depending on your implementation) and either send it to the back (bottom of the hierarchy) or load it first before any other subview/sublayer.

Perhaps backgournd images in IOS 3 wherey doing this within the view/layer and that perhaps Apple decided not double handle the background image versus subview/sublayer and removed support for it.

However, at least you can set the background to a color or even a transparent color. I have verified this.

At any rate, use this workaround until either apple explains why they made this decision or fix the SDK so that it does handle it. I am keen to learn what the apple developer forums have said about this issue (I am certain it has been raised). I am not part of the program just yet as I am still in the alpha stage, once I get to beta, I will register.

Nader