views:

55

answers:

2

I have setup a UITableView (320 wide) with a UITableViewCell created in IB, the cell is also 320 wide. After setting a background image (320 wide) in UITableViewCell (or my subclass to be correct) I have noticed that the cells fall short of the right hand side of the UI (notice the blue on the selected cell and the grey on the one above) Does anyone know what is causing this?

alt text

Cheers Gary

+1  A: 

I was setting the seperator style and the seperator color on the UITableView, this takes 1 pixel off the cell height for the seperator and offsets the backgound by about 5 pixels to the right. If I reduce the background image thats going into the cell from 320x65 to 320x64 it fits perfectly with no offset.

alt text

The only difference between the two screens below is:

LEFT: UITableView Seperator = "None" (UITableViewCell background has no offset)

RIGHT: UITableView Seperator = "Single Line" (UITableViewCell background has offset)

DATA:

  • Cell resolution: 320x65
  • Cell view: 320x65
  • Cell Background Image Resolution: 320x65

If you want use the separator your Cell Background Image needs to be 320x64, this will stop it shifting sideways and display the cell correctly.

Cheers Gary

fuzzygoat
A: 

It seems to me that you're just not setting the contentMode of your background image view correctly (i.e. you're setting it to aspectFit or something). Are you sure that it's offset by 5, and not actually shrunk by 5 pixels?

For example, if the original picture is 320x65, and the height is reduced to 64, aspectFit will scale it, while keeping the same aspect ratio, to 64/65 * 320 ~= 315.

David Liu
Its hard to see as its hidden off the cell edge. The Blue you see on the right is the full highlight you see when you select a cell. If the image was scaled you would expect to see blue showing on the top or bottom too. Also its funny how it magically starts working when you turn off the seperator, so my guess would be its fitted correctly.
fuzzygoat
I just tested this by putting a 1 pixel white border all round a black cell 320x65, with the separator on the border exactly touches all sides of the cell except the right where the white is set back as per the blue below. So the height is right, its the width that scales.
fuzzygoat
If I'm reading you correctly, you have a 320x65 image, all black except for a white border. If that's true, then with the separator on, you're fitting a 320x65 image into a 320x64 view, and that makes the image scale down to 315x64 due to the aspect ratio. Again, setting your contentMode correctly would fix this issue (in this case you'd want scaleToFit).
David Liu