Open-source Chinese IOS client learning-(14th) Use egoimageloading to asynchronously load images

Source: Internet
Author: User

Egoimageloading is a third-party class library that uses a large number of asynchronous image loading methods to simplify the development process. We directly input the image URL. This class library will automatically help us load and cache images asynchronously; when you get an image from the Internet, if the image cannot be downloaded for a short period of time, you can use a local image instead of display. You can also perform other operations, after the image is downloaded, The placeholder image is automatically replaced without affecting the user experience;

GitHub for egoimageloading: https://github.com/enormego/EGOImageLoading

The class library downloaded from GitHub has a demo. If an error occurs, it indicates that the egocache class is missing. In the https://github.com/enormego/egocache?path project, click here to download it directly.

First, let's analyze how the open-source Chinese IOS client uses this third-party class library.

When I search for classes in the client that use this class library, it is not the same as expected. In the project, there are many places where the asynchronous loading of images is required, however, using the egoimageloading class library to load only three places can be said to be two places.

First, it is used when displaying personal data, loading personal images, and displaying personal information.

The second is to show your fans or people you are interested in. When you want to view ta information



In the myview class and userview2 class, the usage is the same

Declare An egoimageview to manage asynchronous image loading

@property (strong,nonatomic) EGOImageView * egoImgView;

In the viewdidload method

// Initialize self. egoimgview = [[egoimageview alloc] initwithframe: cgrectmake (15, 4, 70, 70)]; // placeholder image self. egoimgview. image = [uiimage imagenamed: @ "big_avatar_loading.png"]; // sets the egoimgview of the image rounded corner. layer. cornerradius = 40366f; [self. view addsubview: Self. egoimgview];

Then, in the reload () method, the image is loaded and processed. First, the image URL resource is obtained from network parsing. If the image URL is not obtained, the placeholder image is still displayed, if the image is obtained, replace the placeholder image with the resolved image.

// Avatar nsstring * portrait_str = [tbxml textforelement: Portrait]; If ([portrait_str isequaltostring: @ ""]) {self. egoimgview. image = [uiimage imagenamed: @ "big_avatar.png"];} else {self. egoimgview. imageurl = [nsurl urlwithstring: portrait_str];}

The above is the asynchronous loading of images using the egoimageloading class library;

The following is an example of asynchronous image loading using the egoimageloading class library.
: Http://download.csdn.net/detail/duxinfeng2010/5492125



In the open-source Chinese IOS client's Q & A, movement, and my three views also involve the question of Image Display loading. At first, I mistakenly thought that the egoimageloading class library was used to asynchronously load images, in fact, it is a delayed loading. First, the placeholder image is displayed, and then the icondownloader class library is used to download the image from the server to the local cache for loading and display;





Original blog welcome to repost share, please indicate the source of http://blog.csdn.net/duxinfeng2010


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.