sdwebimage中加载webp格式的图片时需要定义SD_WEBP=1的宏,但由于cocoapod中宏不起作用(我还没找到方法),所以最好是把
sdwebimage代码直接加到项目中,
1.把sdwebimage, 和iOS-webP加入项目中如图
2.在项目中加入SD_WEBP=1宏如图
3.改UIImage+MultiFormat.m文件中的
#ifdef SD_WEBP
else if ([imageContentType isEqualToString:@"image/webp"])
{
image = [UIImage SD_imageWithWebPData:data];
}
#endif
为
#ifdef SD_WEBP
else if ([imageContentType isEqualToString:@"image/webp"])
{
image = [UIImage imageWithWebPData:data];
}
#endif
这样就可以像普通图片一样使用webp图片了