【问题标题】:UITableViewCell Puzzle?UITableViewCell 拼图?
【发布时间】:2011-05-31 07:18:16
【问题描述】:

我正在使用 TableView 并使用 tableViewCell 属性来显示单元格中的图像

cell.imageView.image = aNewsInfo.smallImageData;

但它显示的图像大小与我们通过解析器获得的图像大小相同,因为图像大小不同,我想在单元格中设置此图像帧的大小以显示所有具有相同对齐方式的图像。因为这也是试试这个

cell.imageView.frame = CGRectMake(0, 0, 30, 30);
cell.imageView.image = aNewsInfo.smallImageData;

但它不起作用。请建议解决这个问题的最佳方法...

提前致谢。

【问题讨论】:

    标签: iphone objective-c xcode


    【解决方案1】:

    使用

    cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
    

    来自 Apple UIView 文档。

    UIViewContentModeScaleAspectFit:

    缩放内容以适应 风景。此选项保持 内容的纵横比。任何 视图边界的剩余区域是 透明的。

    【讨论】:

      【解决方案2】:
      UIImageView *myImageView;
      - (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
      
      if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
      [self.contentView addSubview:myImageView];
      }
      - (void)layoutSubviews {
      frame= CGRectMake(0 ,0, 50, 50);
      
      myImageView.frame = frame;
      }
      

      //在索引路径的行中的单元格中

      cell.myImageView.image = [UIImage imageNamed:@"calendar_color.png"];
      

      盗自here

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-10-24
        • 2016-08-05
        • 2011-11-14
        相关资源
        最近更新 更多