【问题标题】:Content mode issue in UIImageView when its set to ASpectFillUIImageView 设置为 ASpectFill 时的内容模式问题
【发布时间】:2012-07-24 14:46:09
【问题描述】:

我需要在一个单元格中加载一个图像,我的图像上有一个白色边框。我从链接调用图像,它看起来像这样。

但我的图像看起来像

我的图像左侧和右侧出现白色边框。这是我的图像代码

    UIImageView *item=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 115, 130)];

    NSString *imgstring=[NSString stringWithFormat: @"%@",[[mutarray objectAtIndex:indexPath.row ] valueForKey:@"imgurl"]];

    NSURL *imgurl=[NSURL URLWithString:imgstring];

    UIImage *image=[UIImage imageWithData:[NSData dataWithContentsOfURL:imgurl]];


    [item setBackgroundColor:[UIColor clearColor]];
    item.contentMode=UIViewContentModeScaleToFill;
    [item setImage:image];
    [cell.contentView addSubview:item];

请指导...

【问题讨论】:

  • 我猜你的图像视图框架大小是错误的。尝试提供一些背景颜色进行测试。就像黄色到单元格背景和绿色到图像视图背景一样。然后将这些图像添加到此处,以便对解决您问题的访问者有所帮助。

标签: ios xcode uitableview uiimageview uiimage


【解决方案1】:

您在问题中发布的图片中包含那些白色的边边框......这就是它们也出现在 iOS 中的原因。在照片编辑器中打开那张照片,你会看到。

【讨论】:

  • 你可以参考链接例如...http:\/\/shop.minora.com.sg\/img\/p\/72-117-large.jpg..这是原始图像..你可以看到该图像中没有白色边框..
  • 嗯,是的……链接与您在问题中发布的链接完全相同:300x300 像素,每侧约 37 像素的白色。
  • 图片两边都有白色边框。
  • 是的,有白色边框可用,在你的mac机器的预览软件中打开该图像,在预览中设置背景颜色为黑色。你会受到关注。
【解决方案2】:

你可以通过编辑webimage来解决它,因为它有白色背景,你可以添加以下代码来区分图像

item.backgroundcolor=[UIColor blackcolor];

希望对你有帮助..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-06
    • 1970-01-01
    • 1970-01-01
    • 2023-04-05
    • 2018-03-06
    • 1970-01-01
    相关资源
    最近更新 更多