Set UIImageView image using a url

后端 未结 10 716
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 02:24

Is it possible to read a url to an image and set a UIImageView to the image at this url?

10条回答
  •  -上瘾入骨i
    2020-12-08 02:52

    EGOImageLoading

    EGOImageView* imageView = [[EGOImageView alloc] initWithPlaceholderImage:[UIImage imageNamed:@"placeholder.png"]];
    imageView.frame = CGRectMake(0.0f, 0.0f, 36.0f, 36.0f);
    
    //show the placeholder image instantly
    [self.anyView addSubview:imageView];
    [imageView release] //if you want
    
    //load the image from url asynchronously with caching automagically
    imageView.imageURL = [NSURL URLWithString:photoURL]; 
    

    If you want more, there is a delegate to handle actions after loading

    @protocol EGOImageViewDelegate
    @optional
    - (void)imageViewLoadedImage:(EGOImageView*)imageView;
    - (void)imageViewFailedToLoadImage:(EGOImageView*)imageView error:(NSError*)error;
    @end
    

提交回复
热议问题