|
@@ -6,8 +6,15 @@ YYWebImage <a href="#中文介绍">中文介绍</a>
|
|
|
[](http://cocoapods.org/?q= YYWebImage)
|
|
|
[](https://www.apple.com/nl/ios/)
|
|
|
|
|
|
-Asynchronous image loading framework.<br/>
|
|
|
-(It's a component of [YYKit](https://github.com/ibireme/YYKit))
|
|
|
+
|
|
|
+
|
|
|
+YYWebImage is an asynchronous image loading framework (a component of [YYKit](https://github.com/ibireme/YYKit)).
|
|
|
+
|
|
|
+It was created as an improved replacement for SDWebImage, PINRemoteImage and FLAnimatedImage.
|
|
|
+
|
|
|
+It use [YYCache](https://github.com/ibireme/YYCache) to support memory and disk cache, and [YYImage](https://github.com/ibireme/YYImage) to support WebP/APNG/GIF image decode.<br/>
|
|
|
+See these project for more information.
|
|
|
|
|
|
|
|
|
Features
|
|
@@ -18,6 +25,220 @@ Features
|
|
|
- Image loading category for UIImageView, UIButton, MKAnnotationView and CALayer.
|
|
|
- High performance memory and disk image cache.
|
|
|
- High performance image loader to avoid main thread blocked.
|
|
|
+- Image effect: blur, round corner, resize, color tint, crop, rotate and more.
|
|
|
+
|
|
|
+Usage
|
|
|
+==============
|
|
|
+
|
|
|
+###Load image from URL
|
|
|
+
|
|
|
+ // load from remote url
|
|
|
+ imageView.yy_imageURL = [NSURL URLWithString:@"http://github.com/logo.png"];
|
|
|
+
|
|
|
+ // load from local url
|
|
|
+ imageView.yy_imageURL = [NSURL fileURLWithPath:@"/tmp/logo.png"];
|
|
|
+
|
|
|
+
|
|
|
+###Load animated image
|
|
|
+
|
|
|
+ // just replace `UIImageView` with `YYAnimatedImageView`
|
|
|
+ UIImageView *imageView = [YYAnimatedImageView new];
|
|
|
+ imageView.yy_imageURL = [NSURL URLWithString:@"http://github.com/ani.webp"];
|
|
|
+
|
|
|
+
|
|
|
+###Load image progressively
|
|
|
+
|
|
|
+ // progressive
|
|
|
+ [imageView yy_setImageWithURL:url options:YYWebImageOptionProgressive];
|
|
|
+
|
|
|
+ // progressive with blur and fade animation (see the demo at the top of this page)
|
|
|
+ [imageView yy_setImageWithURL:url options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
|
|
|
+
|
|
|
+
|
|
|
+###Load and process image
|
|
|
+
|
|
|
+ // 1. download image from remote
|
|
|
+ // 2. get download progress
|
|
|
+ // 3. resize image and add round corner
|
|
|
+ // 4. set image with a fade animation
|
|
|
+
|
|
|
+ [imageView yy_setImageWithURL:url
|
|
|
+ placeholder:nil
|
|
|
+ options:YYWebImageOptionSetImageWithFadeAnimation
|
|
|
+ progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
|
|
+ progress = receivedSize / expectedSize;
|
|
|
+ }
|
|
|
+ transform:^UIImage *(UIImage *image, NSURL *url) {
|
|
|
+ image = [image yy_imageByResizeToSize:CGSizeMake(100, 100) contentMode:UIViewContentModeCenter];
|
|
|
+ return [image yy_imageByRoundCornerRadius:10];
|
|
|
+ }
|
|
|
+ completion:^(UIImage *image, NSURL *url, YYWebImageFromType from, YYWebImageStage stage, NSError *error) {
|
|
|
+ if (from == YYWebImageFromDiskCache) {
|
|
|
+ NSLog(@"load from disk cache");
|
|
|
+ }
|
|
|
+ }];
|
|
|
+
|
|
|
+Installation
|
|
|
+==============
|
|
|
+
|
|
|
+### Cocoapods (unavailable temporarily)
|
|
|
+
|
|
|
+1. Update cocoapods to the latest version.
|
|
|
+1. Add `pod "YYWebImage"` to your Podfile.
|
|
|
+2. Run `pod install` or `pod update`.
|
|
|
+3. Import \<YYWebImage/YYWebImage.h\>
|
|
|
+
|
|
|
+
|
|
|
+### Carthage
|
|
|
+
|
|
|
+1. Add `github "ibireme/YYWebImage"` to your Cartfile.
|
|
|
+2. Run `carthage update --platform ios` and add the framework to your project.
|
|
|
+3. Import \<YYWebImage/YYWebImage.h\>
|
|
|
+4. Notice: carthage framework doesn't include webp component, if you want to support webp, use cocoapods or install manually.
|
|
|
+
|
|
|
+### Manually
|
|
|
+
|
|
|
+1. Download all the files in the YYWebImage subdirectory.
|
|
|
+2. Add the source files to your Xcode project.
|
|
|
+3. Link with required frameworks:
|
|
|
+ * UIKit.framework
|
|
|
+ * CoreFoundation.framework
|
|
|
+ * QuartzCore.framework
|
|
|
+ * AssetsLibrary.framework
|
|
|
+ * ImageIO.framework
|
|
|
+ * Accelerate.framework
|
|
|
+ * MobileCoreServices.framework
|
|
|
+ * libsqlite3
|
|
|
+ * libz
|
|
|
+4. Add `Vendor/WebP.framework`(static library) to your Xcode project if you want to support webp.
|
|
|
+5. Import `YYWebImage.h`.
|
|
|
+
|
|
|
+
|
|
|
+About
|
|
|
+==============
|
|
|
+This library supports iOS 6.0 and later.
|
|
|
+
|
|
|
+
|
|
|
+License
|
|
|
+==============
|
|
|
+YYImage is provided under the MIT license. See LICENSE file for details.
|
|
|
+
|
|
|
+
|
|
|
+<br/><br/>
|
|
|
+---
|
|
|
+中文介绍
|
|
|
+==============
|
|
|
|
|
|
-
|
|
|
+YYWebImage 是一个异步图片加载框架 ([YYKit](https://github.com/ibireme/YYKit) 组件之一).
|
|
|
+
|
|
|
+其设计目的是试图替代 SDWebImage、PINRemoteImage、FLAnimatedImage 等开源框架,它支持这些开源框架的几乎所有的功能,同时增加了大量新特性、并且有不小的性能提升。
|
|
|
+
|
|
|
+它底层用 [YYCache](https://github.com/ibireme/YYCache) 实现了内存和磁盘缓存, 用 [YYImage](https://github.com/ibireme/YYImage) 实现了 WebP/APNG/GIF 动图的解码和播放。<br/>
|
|
|
+你可以查看这些项目以获得更多信息。
|
|
|
+
|
|
|
+
|
|
|
+特性
|
|
|
+==============
|
|
|
+- 异步的图片加载,支持 HTTP 和本地文件。
|
|
|
+- 支持 WebP、APNG、GIF 动画。
|
|
|
+- 支持逐行扫描、隔行扫描、渐进式图像加载。
|
|
|
+- UIImageView、UIButton、MKAnnotationView、CALayer 的 Category 方法支持。
|
|
|
+- 高性能的内存和磁盘缓存。
|
|
|
+- 高性能的图片设置方式,以避免主线程阻塞。
|
|
|
+- 常见图片处理:模糊、圆角、大小调整、裁切、旋转、色调等。
|
|
|
+
|
|
|
+用法
|
|
|
+==============
|
|
|
+
|
|
|
+###从 URL 加载图片
|
|
|
+
|
|
|
+ // 加载网络图片
|
|
|
+ imageView.yy_imageURL = [NSURL URLWithString:@"http://github.com/logo.png"];
|
|
|
+
|
|
|
+ // 加载本地图片
|
|
|
+ imageView.yy_imageURL = [NSURL fileURLWithPath:@"/tmp/logo.png"];
|
|
|
+
|
|
|
+
|
|
|
+###加载动图
|
|
|
+
|
|
|
+ // 只需要把 `UIImageView` 替换为 `YYAnimatedImageView` 即可。
|
|
|
+ UIImageView *imageView = [YYAnimatedImageView new];
|
|
|
+ imageView.yy_imageURL = [NSURL URLWithString:@"http://github.com/ani.webp"];
|
|
|
+
|
|
|
+
|
|
|
+###渐进式图片加载
|
|
|
+
|
|
|
+ // 渐进式:边下载边显示
|
|
|
+ [imageView yy_setImageWithURL:url options:YYWebImageOptionProgressive];
|
|
|
+
|
|
|
+ // 渐进式加载,增加模糊效果和渐变动画 (见本页最上方的GIF演示)
|
|
|
+ [imageView yy_setImageWithURL:url options:YYWebImageOptionProgressiveBlur | YYWebImageOptionSetImageWithFadeAnimation];
|
|
|
+
|
|
|
+
|
|
|
+###加载、处理图片
|
|
|
+
|
|
|
+ // 1. 下载图片
|
|
|
+ // 2. 获得图片下载进度
|
|
|
+ // 3. 调整图片大小、加圆角
|
|
|
+ // 4. 显示图片时增加一个淡入动画,以获得更好的用户体验
|
|
|
+
|
|
|
+ [imageView yy_setImageWithURL:url
|
|
|
+ placeholder:nil
|
|
|
+ options:YYWebImageOptionSetImageWithFadeAnimation
|
|
|
+ progress:^(NSInteger receivedSize, NSInteger expectedSize) {
|
|
|
+ progress = receivedSize / expectedSize;
|
|
|
+ }
|
|
|
+ transform:^UIImage *(UIImage *image, NSURL *url) {
|
|
|
+ image = [image yy_imageByResizeToSize:CGSizeMake(100, 100) contentMode:UIViewContentModeCenter];
|
|
|
+ return [image yy_imageByRoundCornerRadius:10];
|
|
|
+ }
|
|
|
+ completion:^(UIImage *image, NSURL *url, YYWebImageFromType from, YYWebImageStage stage, NSError *error) {
|
|
|
+ if (from == YYWebImageFromDiskCache) {
|
|
|
+ NSLog(@"load from disk cache");
|
|
|
+ }
|
|
|
+ }];
|
|
|
+
|
|
|
+安装
|
|
|
+==============
|
|
|
+
|
|
|
+### Cocoapods (还没提交,暂时不可用)
|
|
|
+
|
|
|
+1. 将 cocoapods 更新至最新版本.
|
|
|
+1. 在 Podfile 中添加 `pod "YYWebImage"`。
|
|
|
+2. 执行 `pod install` 或 `pod update`。
|
|
|
+3. 导入 \<YYWebImage/YYWebImage.h\>。
|
|
|
+
|
|
|
+
|
|
|
+### Carthage
|
|
|
+
|
|
|
+1. 在 Cartfile 中添加 `github "ibireme/YYWebImage"`。
|
|
|
+2. 执行 `carthage update --platform ios` 并将生成的 framework 添加到你的工程。
|
|
|
+3. 导入 \<YYWebImage/YYWebImage.h\>。
|
|
|
+4. 注意: carthage framework 并没有包含 webp 组件。如果你需要支持 webp,可以用 Cocoapods 安装,或者手动安装。
|
|
|
+
|
|
|
+### Manually
|
|
|
+
|
|
|
+1. 下载 YYWebImage 文件夹内的所有内容。
|
|
|
+2. 将 YYWebModel 内的源文件添加(拖放)到你的工程。
|
|
|
+3. 链接以下 frameworks:
|
|
|
+ * UIKit.framework
|
|
|
+ * CoreFoundation.framework
|
|
|
+ * QuartzCore.framework
|
|
|
+ * AssetsLibrary.framework
|
|
|
+ * ImageIO.framework
|
|
|
+ * Accelerate.framework
|
|
|
+ * MobileCoreServices.framework
|
|
|
+ * libsqlite3
|
|
|
+ * libz
|
|
|
+4. 如果你需要支持 webp,可以将 `Vendor/WebP.framework`(静态库) 加入你的工程。
|
|
|
+5. 导入 `YYWebImage.h`。
|
|
|
+
|
|
|
+
|
|
|
+关于
|
|
|
+==============
|
|
|
+该项目最低支持 iOS 6.0。
|
|
|
+
|
|
|
+
|
|
|
+许可证
|
|
|
+==============
|
|
|
+YYWebImage 使用 MIT 许可证,详情见 LICENSE 文件。
|