views:

318

answers:

1

I know this seems like a simple task, which is why I don't understand why I can't get the image to render.

When I set up my UIView, I do the following:

myUiView.backgroundColor = [UIColor clearColor];
myUiView.opaque = NO;

I create and retain the UIImage in the init function of my UIView:

image = [[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"png"]] retain];

then my drawRect looks like this:

- (void) drawRect:(CGRect) rect
{
    [image drawInRect:self.bounds];
}

Ultimately I'll be manipulating that UIImage via bitmap context, and then in drawRect create a CGImage out of the context, and render that, but for now I'm just trying to get it rendering a known image.

I've been digging through this site, as well as the documentation. I've gone down the CG path and tried drawing it with CGContextDrawImage by following the numerous examples other people have posted, but that didn't work either.

So I've come back to what seems to be the most straightforward way to draw an image, but it isn't working.

Any help would be greatly appreciated.

Thanks in advance.

+1  A: 

First of all, verify that the size and position of self.bounds are what you want them to be. If the size is {0,0} nothing will display. Check using this function:

NSLog(@"%@", NSStringFromCGRect(self.bounds));

Also make sure that the image is not nil:

NSLog(@"%@", image);

macatomy