Giter VIP home page Giter VIP logo

lcwebimage's Introduction

LCWebImage

LCWebImage is an asynchronous image loading framework based on AFNetworking, which supports memory and disk caching, and provides functions such as custom caching, custom image decoding, and custom network configuration.

Animation playback is not supported by default. If you need to support animation, you can implement custom decoding (such as YYImage).

Requirements

  • iOS 9.0+
  • Xcode 11.0+
  • AFNetworking 4.0+

Usage

Load image

// UIImageView
[imageView lc_setImageWithURL:[NSURL URLWithString:@"https://xxx"]];

// UIButton
[button lc_setImageWithURL:[NSURL URLWithString:@"https://xxx"] forState:(UIControlStateNormal)];

Custom decoding playback animation

Use YYImage to implement custom decoding

// custom
[(LCAutoPurgingImageCache *)[LCImageDownloader defaultInstance].imageCache setCustomDecodedImage:^UIImage * _Nonnull(NSData * _Nonnull data, NSString * _Nonnull identifier) {
    return [[YYImage alloc] initWithData:data scale:UIScreen.mainScreen.scale];
}];

Load image

YYAnimatedImageView *imageView = [[YYAnimatedImageView alloc] init];
[imageView lc_setImageWithURL:[NSURL URLWithString:@"https://xxx"]];

Note: There is a display problem with YYImage above iOS 14. The source code of YYAnimatedImageView needs to be modified as follows:

- (void)displayLayer:(CALayer *)layer {
    // modified code
    UIImage *currentFrame = _curFrame;
    if (currentFrame) {
        layer.contentsScale = currentFrame.scale;
        layer.contents = (__bridge id)currentFrame.CGImage;
    } else {
        // If we have no animation frames, call super implementation. iOS 14+ UIImageView use this delegate method for rendering.
        if ([UIImageView instancesRespondToSelector:@selector(displayLayer:)]) {
           [super displayLayer:layer];
        }
    }

    // source code
//    if (_curFrame) {
//        layer.contents = (__bridge id)_curFrame.CGImage;
//    }
}

Installation

CocoaPods

To integrate LCWebImage into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'LCWebImage'

Manual

  1. Download everything inside the LCWebImage folder;
  2. Add (drag and drop) the source files in LCWebImage to your project;
  3. Add AFNetworking/NSURLSession code.

License

LCWebImage is provided under the MIT license. See LICENSE file for details.

lcwebimage's People

Contributors

gly avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.