You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

203 lines
8.7 KiB

  1. <p align="center">
  2. <img src="SDWebImage_logo.png" title="SDWebImage logo" float=left>
  3. </p>
  4. [![Build Status](http://img.shields.io/travis/SDWebImage/SDWebImage/master.svg?style=flat)](https://travis-ci.org/SDWebImage/SDWebImage)
  5. [![Pod Version](http://img.shields.io/cocoapods/v/SDWebImage.svg?style=flat)](http://cocoadocs.org/docsets/SDWebImage/)
  6. [![Pod Platform](http://img.shields.io/cocoapods/p/SDWebImage.svg?style=flat)](http://cocoadocs.org/docsets/SDWebImage/)
  7. [![Pod License](http://img.shields.io/cocoapods/l/SDWebImage.svg?style=flat)](https://www.apache.org/licenses/LICENSE-2.0.html)
  8. [![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/SDWebImage/SDWebImage)
  9. [![codecov](https://codecov.io/gh/SDWebImage/SDWebImage/branch/master/graph/badge.svg)](https://codecov.io/gh/SDWebImage/SDWebImage)
  10. This library provides an async image downloader with cache support. For convenience, we added categories for UI elements like `UIImageView`, `UIButton`, `MKAnnotationView`.
  11. ## Features
  12. - [x] Categories for `UIImageView`, `UIButton`, `MKAnnotationView` adding web image and cache management
  13. - [x] An asynchronous image downloader
  14. - [x] An asynchronous memory + disk image caching with automatic cache expiration handling
  15. - [x] A background image decompression
  16. - [x] A guarantee that the same URL won't be downloaded several times
  17. - [x] A guarantee that bogus URLs won't be retried again and again
  18. - [x] A guarantee that main thread will never be blocked
  19. - [x] Performances!
  20. - [x] Use GCD and ARC
  21. ## Supported Image Formats
  22. - Image formats supported by UIImage (JPEG, PNG, ...), including GIF
  23. - WebP format, including animated WebP (use the `WebP` subspec)
  24. - Support extendable coder plugins for new image formats. Like APNG, BPG, HFIF, SVG, etc. See all the list in [Image coder plugin List](https://github.com/SDWebImage/SDWebImage/wiki/Coder-Plugin-List)
  25. ## Beta version
  26. SDWebImage's 5.0 version is nearing completion. Which introduce many new features like Animated ImageView and Transformer. We also provide a more modularized design used for advanced user customization.
  27. You can check the latest [5.x branch](https://github.com/SDWebImage/SDWebImage/tree/5.x) to know about the current status. We'd love you to have a try with the beta version and provide any feedback. If you'd love, check [SDWebImage 5.0 Migration Guide](https://github.com/SDWebImage/SDWebImage/wiki/5.0-Migration-guide) and prepare for the migration.
  28. ## Requirements
  29. - iOS 7.0 or later
  30. - tvOS 9.0 or later
  31. - watchOS 2.0 or later
  32. - macOS 10.9 or later
  33. - Xcode 7.3 or later
  34. #### Backwards compatibility
  35. - For iOS 5 and 6, use [any 3.x version up to 3.7.6](https://github.com/SDWebImage/SDWebImage/tree/3.7.6)
  36. - For iOS < 5.0, please use the last [2.0 version](https://github.com/SDWebImage/SDWebImage/tree/2.0-compat).
  37. ## Getting Started
  38. - Read this Readme doc
  39. - Read the [How to use section](https://github.com/SDWebImage/SDWebImage#how-to-use)
  40. - Read the [Documentation @ CocoaDocs](http://cocoadocs.org/docsets/SDWebImage/)
  41. - Try the example by downloading the project from Github or even easier using CocoaPods try `pod try SDWebImage`
  42. - Read the [Installation Guide](https://github.com/SDWebImage/SDWebImage/wiki/Installation-Guide)
  43. - Read the [SDWebImage 4.0 Migration Guide](Docs/SDWebImage-4.0-Migration-guide.md) to get an idea of the changes from 3.x to 4.x
  44. - Read the [Common Problems](https://github.com/SDWebImage/SDWebImage/wiki/Common-Problems) to find the solution for common problems
  45. - Go to the [Wiki Page](https://github.com/SDWebImage/SDWebImage/wiki) for more information such as [Advanced Usage](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage)
  46. ## Who Uses It
  47. - Find out [who uses SDWebImage](https://github.com/SDWebImage/SDWebImage/wiki/Who-Uses-SDWebImage) and add your app to the list.
  48. ## Communication
  49. - If you **need help**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/sdwebimage). (Tag 'sdwebimage')
  50. - If you'd like to **ask a general question**, use [Stack Overflow](http://stackoverflow.com/questions/tagged/sdwebimage).
  51. - If you **found a bug**, open an issue.
  52. - If you **have a feature request**, open an issue.
  53. - If you **want to contribute**, submit a pull request.
  54. ## How To Use
  55. * Objective-C
  56. ```objective-c
  57. #import <SDWebImage/UIImageView+WebCache.h>
  58. ...
  59. [imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
  60. placeholderImage:[UIImage imageNamed:@"placeholder.png"]];
  61. ```
  62. * Swift
  63. ```swift
  64. import SDWebImage
  65. imageView.sd_setImage(with: URL(string: "http://www.domain.com/path/to/image.jpg"), placeholderImage: UIImage(named: "placeholder.png"))
  66. ```
  67. - For details about how to use the library and clear examples, see [The detailed How to use](Docs/HowToUse.md)
  68. ## Animated Images (GIF) support
  69. - Starting with the 4.0 version, we rely on [FLAnimatedImage](https://github.com/Flipboard/FLAnimatedImage) to take care of our animated images.
  70. - If you use cocoapods, add `pod 'SDWebImage/GIF'` to your podfile.
  71. - To use it, simply make sure you use `FLAnimatedImageView` instead of `UIImageView`.
  72. - **Note**: there is a backwards compatible feature, so if you are still trying to load a GIF into a `UIImageView`, it will only show the 1st frame as a static image by default. However, you can enable the full GIF support by using the built-in GIF coder. See [GIF coder](https://github.com/SDWebImage/SDWebImage/wiki/Advanced-Usage#gif-coder)
  73. - **Important**: FLAnimatedImage only works on the iOS platform. For macOS, use `NSImageView` with `animates` set to `YES` to show the entire animated images and `NO` to only show the 1st frame. For all the other platforms (tvOS, watchOS) we will fallback to the backwards compatibility feature described above
  74. ## Installation
  75. There are three ways to use SDWebImage in your project:
  76. - using CocoaPods
  77. - using Carthage
  78. - by cloning the project into your repository
  79. ### Installation with CocoaPods
  80. [CocoaPods](http://cocoapods.org/) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries in your projects. See the [Get Started](http://cocoapods.org/#get_started) section for more details.
  81. #### Podfile
  82. ```
  83. platform :ios, '7.0'
  84. pod 'SDWebImage', '~> 4.0'
  85. ```
  86. ##### Swift and static framework
  87. Swift project previously have to use `use_frameworks!` to make all Pods into dynamic framework to let CocoaPods works.
  88. However, start with `CocoaPods 1.5.0+` (with `Xcode 9+`), which supports to build both Objective-C && Swift code into static framework. You can use modular headers to use SDWebImage as static framework, without the need of `use_frameworks!`:
  89. ```
  90. platform :ios, '8.0'
  91. # Uncomment the next line when you want all Pods as static framework
  92. # use_modular_headers!
  93. pod 'SDWebImage', :modular_headers => true
  94. ```
  95. See more on [CocoaPods 1.5.0 — Swift Static Libraries](http://blog.cocoapods.org/CocoaPods-1.5.0/)
  96. If not, you still need to add `use_frameworks!` to use SDWebImage as dynamic framework:
  97. ```
  98. platform :ios, '8.0'
  99. use_frameworks!
  100. pod 'SDWebImage'
  101. ```
  102. #### Subspecs
  103. There are 4 subspecs available now: `Core`, `MapKit`, `GIF` and `WebP` (this means you can install only some of the SDWebImage modules. By default, you get just `Core`, so if you need `WebP`, you need to specify it).
  104. Podfile example:
  105. ```
  106. pod 'SDWebImage/WebP'
  107. ```
  108. ### Installation with Carthage (iOS 8+)
  109. [Carthage](https://github.com/Carthage/Carthage) is a lightweight dependency manager for Swift and Objective-C. It leverages CocoaTouch modules and is less invasive than CocoaPods.
  110. To install with carthage, follow the instruction on [Carthage](https://github.com/Carthage/Carthage)
  111. #### Cartfile
  112. ```
  113. github "SDWebImage/SDWebImage"
  114. ```
  115. ### Installation by cloning the repository
  116. - see [Manual install](Docs/ManualInstallation.md)
  117. ### Import headers in your source files
  118. In the source files where you need to use the library, import the header file:
  119. ```objective-c
  120. #import <SDWebImage/UIImageView+WebCache.h>
  121. ```
  122. ### Build Project
  123. At this point your workspace should build without error. If you are having problem, post to the Issue and the
  124. community can help you solve it.
  125. ## Author
  126. - [Olivier Poitrey](https://github.com/rs)
  127. ## Collaborators
  128. - [Konstantinos K.](https://github.com/mythodeia)
  129. - [Bogdan Poplauschi](https://github.com/bpoplauschi)
  130. - [Chester Liu](https://github.com/skyline75489)
  131. - [DreamPiggy](https://github.com/dreampiggy)
  132. - [Wu Zhong](https://github.com/zhongwuzw)
  133. ## Licenses
  134. All source code is licensed under the [MIT License](https://raw.github.com/SDWebImage/SDWebImage/master/LICENSE).
  135. ## Architecture
  136. <p align="center">
  137. <img src="Docs/SDWebImageClassDiagram.png" title="SDWebImage class diagram">
  138. </p>
  139. <p align="center">
  140. <img src="Docs/SDWebImageSequenceDiagram.png" title="SDWebImage sequence diagram">
  141. </p>