说明:
SDWebImage是图片加载框架,能自动将图片下载并显示到UIImageView上。
一、将SDWebImage导入工程:
1.到SDWebImage GitHub上下载”SDWebImage-master”,将SDWebImage-master目录下的”SDWebImage”整个文件夹拖入工程根目录下。
2.按”Command+B”编译工程,解决报错问题,最新的会报2个类别的错误:
(1)Implicit declaration of function 'SD_LOCK' is invalid in C99解决办法:
在报错的文件中加入:
#import "SDInternalMacros.h"
(2)Unexpected '@' in program解决办法:
直接注掉报错的类似这种代码(懒得改,反正注掉也能用):
@weakify(self);
二、使用SDWebImage加载图片并显示到UIImageView上:
/*
显示图片到UIImageView上
*/
- (void)showImg:(UIImageView *)imgIv{
//参数1为图片Url,参数2为默认显示图片
[self.imgIv sd_setImageWithURL:[NSURL URLWithString:@"https://img.zcool.cn/community/01877d56f396d732f875a9441bd852.jpg@1280w_1l_2o_100sh.jpg"]
placeholderImage:[UIImage imageNamed:@"img_default.png"]];
}
本文介绍如何将SDWebImage图片加载框架导入工程,并解决常见错误。同时,提供了使用示例,展示如何利用该框架加载并显示网络图片到UIImageView上。

3806

被折叠的 条评论
为什么被折叠?



