【问题标题】:Fit image to UIImageVIew in a table view cell使图像适合表格视图单元格中的 UIImageVIew
【发布时间】:2012-03-30 11:53:11
【问题描述】:

我正在尝试使用此代码在表格视图单元格中从 UIImageVI 中的 URL 调用的图像居中并使其居中:

NSData *imageData= [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:news.image_small]];

    cell.imageView.image=[UIImage imageWithData:imageData];

    cell.imageView.layer.cornerRadius = 5.0;

    cell.imageView.layer.masksToBounds = YES;

    cell.imageView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    cell.imageView.layer.borderWidth = 1.0;

    cell.imageView.contentMode = UIViewContentModeScaleAspectFit;

但是图像总是大于 UIImageVI 的大小。我该如何解决?

非常感谢

朋友

【问题讨论】:

    标签: objective-c ios5


    【解决方案1】:

    要使图片与 UIImageView 大小相等,最好替换:

    cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
    

    作者:

    cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
    

    希望这会有所帮助;)

    【讨论】:

      猜你喜欢
      • 2019-06-21
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2014-05-05
      • 2023-03-28
      • 2019-12-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多