【问题标题】:Image resizes after async download AFNetworking UiTableView异步下载后图像调整大小 AFNetworking UiTableView
【发布时间】:2017-12-07 00:59:13
【问题描述】:

我已经实现了 AFNetworking 以将图像异步下载到我的表格中,一切正常,但是当我向下滚动表格时,单元格中的图像会缩小。

我的代码如下所示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    NSDictionary *dictionary = [self.json objectAtIndex:indexPath.row];
    cell.textLabel.text=[dictionary objectForKey:@"name"];
    cell.detailTextLabel.text = [dictionary objectForKey:@"description"];

    NSString *path = [[[[dictionary objectForKey:@"images"] objectAtIndex:0] valueForKey:@"thumb"] valueForKey:@"url"];
    NSString *ruta = [NSString stringWithFormat:@"http://18.221.78.126/ecoferia%@",path];
    NSURL *url = [NSURL URLWithString:ruta];
    [cell.imageView setImageWithURL:url
                      placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
    return cell;
}

这里有一些截图:

picture 1

picture 2

任何提示都会有所不同。 问候。

【问题讨论】:

    标签: ios objective-c uitableview afnetworking


    【解决方案1】:

    在 ios 中有不同类型的内容模式可用于图像视图

    例如,

    1) 通过保持纵横比来缩放内容以适应视图大小的选项。视图边界的任何剩余区域都是透明的。

    cell.imageView.contentMode = UIViewContentModeScaleAspectFit;
    

    2) 缩放内容以填充视图大小的选项。部分内容可能会被剪裁以填充视图的边界。

    cell.imageView.contentMode = UIViewContentModeScaleAspectFill;
    

    3) 如有必要,可通过更改内容的纵横比来缩放内容以适应自身大小。

    cell.imageView.contentMode = UIViewContentModeScaleToFill;
    

    更多详情可以参考Apple Documentation

    • 对于您的评论,您还可以创建自定义 UItableview 单元格或原型单元格在该单元格的 UI 中,您可以为标题添加图像视图和标签并设置 根据您的要求对图像视图进行约束

    【讨论】:

    • 谢谢你的回答,但是这个选项没有效果,当我与桌子互动时,图像仍然缩小。
    • @AndresAldana 我已经更新了我的答案希望对您有所帮助
    【解决方案2】:

    转到单元格并设置 uiimageview 适当的约束,例如 uiimageview hight 和 with

    【讨论】:

      猜你喜欢
      • 2013-07-14
      • 1970-01-01
      • 2012-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-29
      • 1970-01-01
      相关资源
      最近更新 更多