Loading images in background to optimize the loading in ios

后端 未结 9 1260
星月不相逢
星月不相逢 2021-02-02 03:02

I am trying to optimize the load in my application, in fact, I have a lot of images that loaded in my application, and I spend a lot of time waiting for a view controller to ope

9条回答
  •  北荒
    北荒 (楼主)
    2021-02-02 03:36

    Take a look at this control: https://github.com/nicklockwood/AsyncImageView

    It's very easy to implement (only 1 header file) and will suit your needs just fine.

    Using this control: Instead of declaring:

    NSURL *imageURL = ......;
    NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
    UIImage *imageLoad;
    imageLoad = [[UIImage alloc] initWithData:imageData];
    imageView.image = imageLoad;
    

    Use:

    NSURL *imageURL = ......;
    imageView.imageURL = imageURL;
    

提交回复
热议问题