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.

168 lines
11 KiB

  1. <p align="center">
  2. <img src="https://raw.githubusercontent.com/onevcat/Kingfisher/master/images/logo.png" alt="Kingfisher" title="Kingfisher" width="557"/>
  3. </p>
  4. <p align="center">
  5. <a href="https://github.com/onevcat/Kingfisher/actions?query=workflow%3Abuild"><img src="https://github.com/onevcat/kingfisher/workflows/build/badge.svg?branch=master"></a>
  6. <a href="http://onevcat.github.io/Kingfisher/"><img src="https://img.shields.io/cocoapods/v/Kingfisher.svg?style=flat"></a>
  7. <a href="https://github.com/Carthage/Carthage/"><img src="https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat"></a>
  8. <a href="https://swift.org/package-manager/"><img src="https://img.shields.io/badge/SPM-supported-DE5C43.svg?style=flat"></a>
  9. <a href="https://github.com/JamitLabs/Accio"><img src="https://img.shields.io/badge/Accio-supported-0A7CF5.svg?style=flat"></a>
  10. <br />
  11. <a href="https://raw.githubusercontent.com/onevcat/Kingfisher/master/LICENSE"><img src="https://img.shields.io/cocoapods/l/Kingfisher.svg?style=flat"></a>
  12. <a href="http://onevcat.github.io/Kingfisher/"><img src="https://img.shields.io/cocoapods/p/Kingfisher.svg?style=flat"></a>
  13. <a href="#backers" alt="sponsors on Open Collective"><img src="https://opencollective.com/Kingfisher/backers/badge.svg" /></a>
  14. <a href="#sponsors" alt="Sponsors on Open Collective"><img src="https://opencollective.com/Kingfisher/sponsors/badge.svg" /></a>
  15. </p>
  16. Kingfisher is a powerful, pure-Swift library for downloading and caching images from the web. It provides you a chance to use a pure-Swift way to work with remote images in your next app.
  17. ## Features
  18. - [x] Asynchronous image downloading and caching.
  19. - [x] Loading image from either `URLSession`-based networking or local provided data.
  20. - [x] Useful image processors and filters provided.
  21. - [x] Multiple-layer hybrid cache for both memory and disk.
  22. - [x] Fine control on cache behavior. Customizable expiration date and size limit.
  23. - [x] Cancelable downloading and auto-reusing previous downloaded content to improve performance.
  24. - [x] Independent components. Use the downloader, caching system and image processors separately as you need.
  25. - [x] Prefetching images and showing them from cache to boost your app.
  26. - [x] View extensions for `UIImageView`, `NSImageView`, `NSButton` and `UIButton` to directly set an image from a URL.
  27. - [x] Built-in transition animation when setting images.
  28. - [x] Customizable placeholder and indicator while loading images.
  29. - [x] Extensible image processing and image format easily.
  30. - [x] SwiftUI support.
  31. ### Kingfisher 101
  32. The simplest use-case is setting an image to an image view with the `UIImageView` extension:
  33. ```swift
  34. let url = URL(string: "https://example.com/image.png")
  35. imageView.kf.setImage(with: url)
  36. ```
  37. Kingfisher will download the image from `url`, send it to both memory cache and disk cache, and display it in `imageView`. When you set with the same URL later, the image will be retrieved from cache and shown immediately.
  38. It also works if you use SwiftUI:
  39. ```swift
  40. import KingfisherSwiftUI
  41. var body: some View {
  42. KFImage(URL(string: "https://example.com/image.png")!)
  43. }
  44. ```
  45. ### A More Advanced Example
  46. With the powerful options, you can do hard tasks with Kingfisher in a simple way. For example, the code below:
  47. 1. Downloads a high-resolution image.
  48. 2. Downsamples it to match the image view size.
  49. 3. Makes it round cornered with a given radius.
  50. 4. Shows a system indicator and a placeholder image while downloading.
  51. 5. When prepared, it animates the small thumbnail image with a "fade in" effect.
  52. 6. The original large image is also cached to disk for later use, to get rid of downloading it again in a detail view.
  53. 7. A console log is printed when the task finishes, either for success or failure.
  54. ```swift
  55. let url = URL(string: "https://example.com/high_resolution_image.png")
  56. let processor = DownsamplingImageProcessor(size: imageView.size)
  57. >> RoundCornerImageProcessor(cornerRadius: 20)
  58. imageView.kf.indicatorType = .activity
  59. imageView.kf.setImage(
  60. with: url,
  61. placeholder: UIImage(named: "placeholderImage"),
  62. options: [
  63. .processor(processor),
  64. .scaleFactor(UIScreen.main.scale),
  65. .transition(.fade(1)),
  66. .cacheOriginalImage
  67. ])
  68. {
  69. result in
  70. switch result {
  71. case .success(let value):
  72. print("Task done for: \(value.source.url?.absoluteString ?? "")")
  73. case .failure(let error):
  74. print("Job failed: \(error.localizedDescription)")
  75. }
  76. }
  77. ```
  78. It is really a very common situation I can meet in my daily work. Think about how many lines you need to write without Kingfisher. You will fall in love with it if you give it a try!
  79. ### Learn More
  80. To learn the using of Kingfisher by more examples, take a look at the [Cheat Sheet](https://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet). There we summarized most common tasks in Kingfisher, you can get a better idea on what this framework can do. There are also some tips for performance in the same page, remember to check them too.
  81. ## Requirements
  82. - iOS 10.0+ / macOS 10.12+ / tvOS 10.0+ / watchOS 3.0+
  83. - Swift 4.0+
  84. [Kingfisher 5.0 Migration](https://github.com/onevcat/Kingfisher/wiki/Kingfisher-5.0-Migration-Guide) - Kingfisher 5.x is NOT fully compatible with version 4.x. However, the migration is not difficult. Depending on your use cases, it may take no effect or several minutes to modify your existing code for the new version. Please follow the [migration guide](https://github.com/onevcat/Kingfisher/wiki/Kingfisher-5.0-Migration-Guide) when you prepare to upgrade Kingfisher in your project.
  85. If you are using an even earlier version, see the guides below to know the steps for migrating.
  86. > - Kingfisher 4.0 Migration - Kingfisher 3.x should be source compatible to Kingfisher 4. The reason for a major update is that we need to specify the Swift version explicitly for Xcode. All deprecated methods in Kingfisher 3 has been removed, so please ensure you have no warning left before you migrate from Kingfisher 3 to Kingfisher 4. If you have any trouble in migrating, please open an issue to discuss.
  87. > - [Kingfisher 3.0 Migration](https://github.com/onevcat/Kingfisher/wiki/Kingfisher-3.0-Migration-Guide) - If you are upgrading to Kingfisher 3.x from an earlier version, please read this for more information.
  88. ## Next Steps
  89. We prepared a [wiki page](https://github.com/onevcat/Kingfisher/wiki). You can find tons of useful things there.
  90. * [Installation Guide](https://github.com/onevcat/Kingfisher/wiki/Installation-Guide) - Follow it to integrate Kingfisher into your project.
  91. * [Cheat Sheet](https://github.com/onevcat/Kingfisher/wiki/Cheat-Sheet)- Curious about what Kingfisher could do and how would it look like when used in your project? See this page for useful code snippets. If you are already familiar with Kingfisher, you could also learn new tricks to improve the way you use Kingfisher!
  92. * [API Reference](http://onevcat.github.io/Kingfisher/) - Lastly, please remember to read the full whenever you may need a more detailed reference.
  93. ## Other
  94. ### Future of Kingfisher
  95. I want to keep Kingfisher lightweight. This framework will focus on providing a simple solution for downloading and caching images. This doesn’t mean the framework can’t be improved. Kingfisher is far from perfect, so necessary and useful updates will be made to make it better.
  96. ### Developments and Tests
  97. Any contributing and pull requests are warmly welcome. However, before you plan to implement some features or try to fix an uncertain issue, it is recommended to open a discussion first. It would be appreciated if your pull requests could build and with all tests green. :)
  98. ### About the logo
  99. The logo of Kingfisher is inspired by [Tangram (七巧板)](http://en.wikipedia.org/wiki/Tangram), a dissection puzzle consisting of seven flat shapes from China. I believe she's a kingfisher bird instead of a swift, but someone insists that she is a pigeon. I guess I should give her a name. Hi, guys, do you have any suggestions?
  100. ### Contact
  101. Follow and contact me on [Twitter](http://twitter.com/onevcat) or [Sina Weibo](http://weibo.com/onevcat). If you find an issue, just [open a ticket](https://github.com/onevcat/Kingfisher/issues/new). Pull requests are warmly welcome as well.
  102. ## Contributors
  103. This project exists thanks to all the people who contribute. [[Contribute]](https://github.com/onevcat/Kingfisher/blob/master/CONTRIBUTING.md).
  104. <a href="https://opencollective.com/kingfisher#backer"><img src="https://opencollective.com/kingfisher/contributors.svg?width=890" /></a>
  105. ## Backers
  106. Thank you to all our backers! Your support is really important for the project and encourages us to continue. 🙏 [[Become a backer](https://opencollective.com/kingfisher#backer)]
  107. <a href="https://opencollective.com/kingfisher#backers" target="_blank"><img src="https://opencollective.com/kingfisher/backers.svg?width=890"></a>
  108. ## Sponsors
  109. Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/kingfisher#sponsor)]
  110. <a href="https://opencollective.com/kingfisher/sponsor/0/website" target="_blank"><img src="https://opencollective.com/kingfisher/sponsor/0/avatar.svg"></a>
  111. <a href="https://opencollective.com/kingfisher/sponsor/1/website" target="_blank"><img src="https://opencollective.com/kingfisher/sponsor/1/avatar.svg"></a>
  112. <a href="https://opencollective.com/kingfisher/sponsor/2/website" target="_blank"><img src="https://opencollective.com/kingfisher/sponsor/2/avatar.svg"></a>
  113. <a href="https://opencollective.com/kingfisher/sponsor/3/website" target="_blank"><img src="https://opencollective.com/kingfisher/sponsor/3/avatar.svg"></a>
  114. <a href="https://opencollective.com/kingfisher/sponsor/4/website" target="_blank"><img src="https://opencollective.com/kingfisher/sponsor/4/avatar.svg"></a>
  115. <a href="https://opencollective.com/kingfisher/sponsor/5/website" target="_blank"><img src="https://opencollective.com/kingfisher/sponsor/5/avatar.svg"></a>
  116. <a href="https://opencollective.com/kingfisher/sponsor/6/website" target="_blank"><img src="https://opencollective.com/kingfisher/sponsor/6/avatar.svg"></a>
  117. <a href="https://opencollective.com/kingfisher/sponsor/7/website" target="_blank"><img src="https://opencollective.com/kingfisher/sponsor/7/avatar.svg"></a>
  118. <a href="https://opencollective.com/kingfisher/sponsor/8/website" target="_blank"><img src="https://opencollective.com/kingfisher/sponsor/8/avatar.svg"></a>
  119. <a href="https://opencollective.com/kingfisher/sponsor/9/website" target="_blank"><img src="https://opencollective.com/kingfisher/sponsor/9/avatar.svg"></a>
  120. ### License
  121. Kingfisher is released under the MIT license. See LICENSE for details.