SDWebImage组件github地址:https://github.com/SDWebImage/SDWebImage
1. 环境配置
pod 里面添加配置:
pod 'SDWebImageWebPCoder' #webp
安装过程抛出错误:
[!] Error installing libwebp
[!] /usr/bin/git clone https://chromium.googlesource.com/webm/libwebp /var/folders/hk/m355x7z92jq6jzk5g0p9svl00000gn/T/d20200422-9362-1s3y79q --template= --single-branch --depth 1 --branch v1.1.0
Cloning into '/var/folders/hk/m355x7z92jq6jzk5g0p9svl00000gn/T/d20200422-9362-1s3y79q'...
fatal: unable to access 'https://chromium.googlesource.com/webm/libwebp/': Failed to connect to chromium.googlesource.com port 443: Operation timed out
打开Finder,Command+shift+G
/Users/用户名/.cocoapods/repos/trunk/Specs/1/9/2/libwebp
打开1.1.0文件,找到 libwebp.podspec.json文件修改
"source": {
"git": "https://chromium.googlesource.com/webm/libwebp",
"tag": "v1.1.0"
}
修改source的git,改为
"git": "https://github.com/webmproject/libwebp.git"
重新更新pod,pod install,OK。
2. 使用SDWebImageWebPCoder
导入文件:
#import <SDWebImage/SDWebImage.h>
#import <SDWebImageWebPCoder/SDWebImageWebPCoder.h>
实现:这个可以写在AppDelegate.m 文件中。
SDImageWebPCoder*webPCoder = [SDImageWebPCoder sharedCoder];
[[SDImageCodersManager sharedManager] addCoder:webPCoder];
使用webp图片
NSString *path = [[NSBundle mainBundle] pathForResource:@"aaa" ofType:@"webp"];
imageView.image = [UIImage sd_imageWithWebPData:[NSData dataWithContentsOfFile:path]];
3. 相关链接
相关链接如下:
网友评论