views:

62

answers:

2

Hello,

I have a custom UIButton with a png inside it. I have quite a few of them in my app and everywhere they seem to be working fine.

In one location they are inside a UIView that is a headerView for a UITableview.

Whenever I press on them, only on iPhone 2G the image box goes black while the rest of the UIButton (it's got a title...) looks fine. After you go out of the view controller and come back the "pressed" image shows fine.

Any ideas why? My images are compressed inside the app file.

Thanks!

UPDATE #1: I used some code that someone graciously offered here on stackoverflow that generates an image from a backcolor so you could put it to use via backgroundImage property. I use it and that seems to be causing the problem. Everytime I press my button it takes my image used and renders a black box instead of it while it displayed the image generated correctly.

- (UIImage *)imageWithColor:(UIColor *)color {
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);

UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

return image;

}

A: 

A bit of a long shot, but is the button set to be "opaque"? In general, turn it off unless you know it's opaque beforehand.

tc.
Tried, didn't work. Put up update #1.
schone
A: 

Solved!

This line of code seems to cause a problem for iOS 3.1.3 (I assume all 3.1).

CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

Once you make the pattern image bigger by atleast 1 pixel you are all good. For example:

CGRect rect = CGRectMake(0.0f, 0.0f, 5.0f, 5.0f);

Solves the problem.

schone