简体   繁体   中英

UITableViewCell strange width?

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?

替代文字

Cheers Gary

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.

替代文字

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

It seems to me that you're just not setting the contentMode of your background image view correctly (ie 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM