views:

598

answers:

1

Hello,

I have a UITableView with standard UITableViewCells that contain an image on the left. I'm setting the image of the cell as follows:

UIImage *leftIcon = [UIImage imageNamed:@"myImage.png"];
cell.imageView.image = leftIcon;

This works fine. However, there's a difference in appearance depending on which iPhone OS the App runs. Until 2.2.1 the image is positioned about 11 pixels from the left border. In 3.0, the image is positioned directly on the left border without any space.

My goal is that the image is positioned about 11px from the left of the cell on 3.0. I tried the following without any success:

UIImage *leftIcon = [UIImage imageNamed:@"myImage.png"];

//trying to change x coordinate of the frame of the UIImageView
CGRect tmpRect = cell.imageView.frame;
tmpRect.origin.x = 10;
cell.imageView.frame = tmpRect;

cell.imageView.image = leftIcon;

I could think of two possible solutions:

1.) Implement my custom UITableViewCell with a custom UIImageView on the left.

2.) Add an 11px transparent border to myImage.png with Photoshop :)

Any recommendations?

A: 

In my opinion, the easiest thing you can do to fix problems like this in the iPhone world is to create custom classes. Also, consider creating some functions for said classes like

-(void)redrawAtDefaultCoordinates;
-(void)redrawAtCoordinates(NSInteger x, NSInteger y);

for each custom class so that you can simply make adjustments to where they are displaying.

As to your actual problem, I would say try to get at the rectangle that the cell uses and then figure out the relative geometry that your going to need. The iPhone does a pretty good job with the guesses it makes about where you want things placed, but you always want at least something to go by if it guesses wrong.

TahoeWolverine