0

I'm a little confused as to why my image isn't sized properly. I am passing in a 44x44 sized image to a UITableView with a default row height of 44 pixels, but I get the following result:

enter image description here

Is this not how I should be setting my UITableViewCell image?

 UIImage *imageOne = [UIImage imageNamed:@"sent-indicator@2x.png"];         
 cell.imageView.image = imageOne;
alexgophermix
  • 4,189
  • 5
  • 32
  • 59
Apollo
  • 8,874
  • 32
  • 104
  • 192
  • As a note, for UIImage imageNamed, don't pass the @2x or the .png. It will assume png and make the retina/non-retina decision automatically. – hukir Nov 27 '13 at 02:03
  • @Apollo Hi! can you accept my answer? :) – Ilario Nov 09 '15 at 09:21

4 Answers4

2

Remove @2x from name of image in code. The system find the retina image

Ilario
  • 5,979
  • 2
  • 32
  • 46
1

A couple of thoughts:

  1. I'd run the app in the debugger, hit the "pause" button, and at the (lldb) prompt, type

    po [[UIWindow keyWindow] recursiveDescription]
    

    That will produce a long cryptic log, but you can confirm the exact screen coordinates. I think you'll find the image view is 43 points high.

    (lldb) po [[UIWindow keyWindow] recursiveDescription]
    <UIWindow: 0x8cb45e0; frame = (0 0; 320 480); gestureRecognizers = <NSArray: 0x8cb1ca0>; layer = <UIWindowLayer: 0x8cb2c70>>
       | <UITableView: 0x9031400; frame = (0 0; 320 480); clipsToBounds = YES; opaque = NO; autoresize = W+H; gestureRecognizers = <NSArray: 0x8a950c0>; layer = <CALayer: 0x8a92ed0>; contentOffset: {0, 0}>
       |    | <UITableViewWrapperView: 0x8a95c10; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x8a95ce0>>
       |    |    | <UITableViewCell: 0x8e9e1b0; frame = (0 440; 320 44); text = 'Row 10'; autoresize = W; layer = <CALayer: 0x8e9d7b0>>
       |    |    |    | <UITableViewCellScrollView: 0x8e9e890; frame = (0 0; 320 44); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x8e9eb20>; layer = <CALayer: 0x8e9ea60>; contentOffset: {0, 0}>
       |    |    |    |    | <UITableViewCellContentView: 0x8e9d7e0; frame = (0 0; 320 43.5); opaque = NO; gestureRecognizers = <NSArray: 0x8e9ee70>; layer = <CALayer: 0x8e9d850>>
       |    |    |    |    |    | <UILabel: 0x8e9e340; frame = (73 0; 232 43.5); text = 'Row 10'; clipsToBounds = YES; layer = <CALayer: 0x8e9e3e0>>
       |    |    |    |    |    | <UIImageView: 0x8e9e620; frame = (15 6; 43 31); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8e9d720>>
       |    |    |    |    | <_UITableViewCellSeparatorView: 0x8e9fb60; frame = (73 43.5; 247 0.5); layer = <CALayer: 0x8e9fbd0>>
       |    |    | <UITableViewCell: 0x8e9d3f0; frame = (0 396; 320 44); text = 'Row 9'; autoresize = W; layer = <CALayer: 0x8e9ca10>>
       |    |    |    | <UITableViewCellScrollView: 0x8e9daf0; frame = (0 0; 320 44); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x8e9dd80>; layer = <CALayer: 0x8e9dcc0>; contentOffset: {0, 0}>
       |    |    |    |    | <UITableViewCellContentView: 0x8e9ca40; frame = (0 0; 320 43.5); opaque = NO; gestureRecognizers = <NSArray: 0x8e9e0d0>; layer = <CALayer: 0x8e9d580>>
       |    |    |    |    |    | <UILabel: 0x8e9d5b0; frame = (73 0; 232 43.5); text = 'Row 9'; clipsToBounds = YES; layer = <CALayer: 0x8e9d650>>
       |    |    |    |    |    | <UIImageView: 0x8e9d880; frame = (15 6; 43 31); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8e9c980>>
       |    |    |    |    | <_UITableViewCellSeparatorView: 0x8e9fa70; frame = (73 43.5; 247 0.5); layer = <CALayer: 0x8e9fae0>>
       |    |    | <UITableViewCell: 0x8e9c620; frame = (0 352; 320 44); text = 'Row 8'; autoresize = W; layer = <CALayer: 0x8e9bc50>>
       |    |    |    | <UITableViewCellScrollView: 0x8e9cd30; frame = (0 0; 320 44); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x8e9cfc0>; layer = <CALayer: 0x8e9cf00>; contentOffset: {0, 0}>
       |    |    |    |    | <UITableViewCellContentView: 0x8e9bc80; frame = (0 0; 320 43.5); opaque = NO; gestureRecognizers = <NSArray: 0x8e9d310>; layer = <CALayer: 0x8e9c7b0>>
       |    |    |    |    |    | <UILabel: 0x8e9c7e0; frame = (73 0; 232 43.5); text = 'Row 8'; clipsToBounds = YES; layer = <CALayer: 0x8e9c880>>
       |    |    |    |    |    | <UIImageView: 0x8e9cac0; frame = (15 6; 43 31); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x8e9bbc0>>
       |    |    |    |    | <_UITableViewCellSeparatorView: 0x8e9f980; frame = (73 43.5; 247 0.5); layer = <CALayer: 0x8e9f9f0>>
    
  2. By the way, that's 43 "points", not "pixels". You might want your @2x rendition to be 86 pixels high, not 43 pixels high. The non-@2x rendition can be 43 pixels high.

Rob
  • 415,655
  • 72
  • 787
  • 1,044
0

The borders of the UITableViewCell are included in the default 44point height of the cell. This means that the default size of the cell's imageView property is actually 40x40 not 44x44 in order to accommodate these borders.

See this answer for more info: https://stackoverflow.com/a/2122183/740474

Community
  • 1
  • 1
alexgophermix
  • 4,189
  • 5
  • 32
  • 59
0

when you specified @2x, you are specifying the image for retina displays which means a 44 x 44 image is actually treated as a 22 x 22 on the retina display. If your cell has a height of 44, then your image should be 88 pixels high.

Nate
  • 403
  • 4
  • 14