UITableView ImageView太大了

时间:2013-11-26 23:14:34

标签: ios objective-c

我有点困惑为什么我的图像尺寸不合适。我将44x44大小的图像传递给UITableView,默认行高为44像素,但我得到以下结果:

enter image description here

这不是我应该如何设置我的UITableViewCell图片吗?

 UIImage *imageOne = [UIImage imageNamed:@"sent-indicator@2x.png"];         
 cell.imageView.image = imageOne;

4 个答案:

答案 0 :(得分:2)

从代码中的图像名称中删除@ 2x。系统找到视网膜图像

答案 1 :(得分:1)

有几点想法:

  1. 我在调试器中运行应用程序,点击“暂停”按钮,然后在(lldb)提示符下键入

    po [[UIWindow keyWindow] recursiveDescription]
    

    这将产生一个长的神秘日志,但您可以确认确切的屏幕坐标。我想你会发现图像视图高43点。

    (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. 顺便说一下,那是43“点”,而不是“像素”。您可能希望@2x再现为86像素高,而不是43像素高。非@2x再现可以是43像素高。

答案 2 :(得分:0)

UITableViewCell的边框包含在单元格的默认44磅高度中。这意味着单元格的imageView属性的默认大小实际上是40x40而不是44x44,以适应这些边界。

有关详细信息,请参阅此答案:https://stackoverflow.com/a/2122183/740474

答案 3 :(得分:0)

当您指定@ 2x时,您指定视网膜显示的图像,这意味着44 x 44图像实际上被视为视网膜显示器上的22 x 22。如果您的单元格高度为44,那么您的图像应该是88像素高。