How to use SDWebImage in my project

百般思念 提交于 2019-12-23 20:16:40

问题


Iam using collectionview to load image.These images are loaded from url in background thread. Hence the scrolling is not smooth.The images in url get expired after seconds hence i want to update the image with new image.How can i use the SDWebImage to load image and make scrolling smooth? Can anyone please help me to solve this.


回答1:


Use this code

[YOUR_CELL_NAME.YOUR_IMAGE_NAME setImageWithURL:[NSURL URLWithString:@"IMAGE URL"] placeholderImage:[UIImage imageNamed:@"PLACEHOLDER IMAGE NAME"]];



回答2:


You need to integrate the sdwebimage classes in your code. After that make a import.

Download sdwebimage from here

#import "UIImageView+WebCache.h"

and in your collectionview method write following lines to download image in backend thread.

[YOUR_CELL_NAME.YOUR_IMAGE_NAME setImageWithURL:[NSURL URLWithString:@"IMAGE URL"] placeholderImage:[UIImage imageNamed:@"PLACEHOLDER IMAGE NAME"]];


来源:https://stackoverflow.com/questions/37432902/how-to-use-sdwebimage-in-my-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!