【问题标题】:Load images using AsyncImageView to ImageView width使用 AsyncImageView 将图像加载到 ImageView 宽度
【发布时间】:2015-08-10 14:07:46
【问题描述】:

我使用AsyncImageView 从 url 加载图像。但是图像没有加载到图像视图宽度。下面是我的代码。

{
    AsyncImageView *asyImage;
    asyImage = [[AsyncImageView alloc] initWithFrame:frame];
    [asyImage loadImageFromURL:[NSURL URLWithString:url]];
    [propertyImage addSubview:asyImage];
    propertyImage.contentMode = UIViewContentModeScaleAspectFit;
}

【问题讨论】:

    标签: ios objective-c json ios7


    【解决方案1】:
     NSString * urlString = @"http://img-paragon.sandicor.com/ParagonImages/Property/Q1/SANDICOR/150016147/0/0/0/729a48630a22f4436d3e45e671bb3548/1/e2d30ecd1633ebc3b6b1f6acbcc77331/150016147.JPG";
    NSData *dataCoverImg = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
    UIImage *imgLocation = [UIImage imageWithData:dataCoverImg];
    self.image = [imgLocation resizedImage:self.propertyImage.frame.size interpolationQuality:kCGInterpolationMedium]; // Can we resize image using UIImage+Resize equel to imageview size
    
    self.urlForTesting=[NSURL URLWithString:urlString];
     CGRect frame = self.propertyImage.bounds; AsyncImageView *asyImage;
    asyImage=[[AsyncImageView alloc] initWithFrame:frame];
    asyImage.imageURL =self.urlForTesting;
    
    
    asyImage.layer.borderWidth = 2.0f;
    asyImage.contentMode = UIViewContentModeScaleToFill;
    asyImage.layer.masksToBounds=YES;
    [self.propertyImage addSubview:asyImage];
    
    self.mySecondImageView.image = self.image; // set directly to asyncimage view with aspect mode AspectFill
    self.myThirdImageView.image = self.image; //Set to normal Image view with aspect Mode ScaleToFill
    // Do any additional setup after loading the view, typically from a nib.
    

    在此代码中,我为您使用了三个图像视图示例,所有这些示例都根据图像视图大小获得完整图像

    【讨论】:

    • 如果您的 url 字符串有转义字符,那么您必须使用 url =[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 对其进行编码
    • 图像正在加载,但与图像视图的宽度不匹配
    • 你想用全宽填充imageview吗?
    • 你必须设置 UIImageView 缩放模式 ScaleToFill 来保存失真设置 AspectFill 而不是 AspectFit
    • 在我的应用程序中,当我需要用完整图像填充图像视图时,我使用了 Scale To Fill 。
    猜你喜欢
    • 2017-12-17
    • 2019-06-27
    • 1970-01-01
    • 1970-01-01
    • 2014-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多