|
|
@@ -1,7 +1,7 @@
|
|
|
@Tutorial(time: 15) {
|
|
|
@Intro(title: "Getting Started with Kingfisher (UIKit)") {
|
|
|
Installs Kingfisher and basic usage of the framework with UIKit.
|
|
|
- @Image(source: "getting-started-card", alt: "")
|
|
|
+ @Image(source: "getting-started-card", alt: "Title image of the tutorial. A kingfisher bird standing on a tree.")
|
|
|
}
|
|
|
|
|
|
@Section(title: "Overview") {
|
|
|
@@ -13,6 +13,8 @@
|
|
|
- Using Kingfisher: Download and display bird images.
|
|
|
- Image Processing: Convert images to rounded corners for display.
|
|
|
- Cache Size Button: A feature to check cache usage.
|
|
|
+
|
|
|
+ @Image(source:preview-4.png, alt:"The first image is loaded into the image view in cell.")
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -61,6 +63,7 @@
|
|
|
@ContentAndMedia {
|
|
|
Creating and setting up `UITableView` is not the focus of this tutorial, as it does not involve Kingfisher.
|
|
|
However, we will later use Kingfisher to manage images in the `UIImageView` within the table cells.
|
|
|
+ @Image(source: preview-1.png, alt: "")
|
|
|
}
|
|
|
|
|
|
@Steps {
|
|
|
@@ -102,13 +105,14 @@
|
|
|
Kingfisher simplifies the task of loading images from remote URLs. It also offers a range of user-friendly
|
|
|
processors and helper methods. In this section, we will cover how to use these features to streamline common
|
|
|
tasks.
|
|
|
+ @Image(source: preview-4.png, alt: "")
|
|
|
}
|
|
|
|
|
|
@Steps {
|
|
|
@Step {
|
|
|
The simplest way to start loading a remote image into an image view in Kingfisher, is using the `kf`
|
|
|
wrapper and its method. In the code above, we already have a `sampleImageView` in the cell.
|
|
|
- @Code(name: "ViewController.swift", file: 01-ViewController-5.swift)
|
|
|
+ @Code(name: "ViewController.swift", file: 01-ViewController-6-0.swift)
|
|
|
}
|
|
|
@Step {
|
|
|
To load the first image, call `kf.setImage(with:)` on the image view, with the desired URL.
|
|
|
@@ -159,11 +163,23 @@
|
|
|
First we want to tell the space that is taken by the image cache. For the sake of simplicity, we are
|
|
|
not going to add any additional button to this sample. But usually the calculation is triggered by a
|
|
|
button or navigation, and the result is displayed in a label.
|
|
|
- @Code(name: "ViewController.swift", file: 01-ViewController-9.swift)
|
|
|
+ @Code(name: "ViewController.swift", file: 01-ViewController-10.swift)
|
|
|
}
|
|
|
@Step {
|
|
|
- In `viewDidLoad`, we call
|
|
|
- @Code(name: "ViewController.swift", file: 01-ViewController-10.swift)
|
|
|
+ In `viewDidLoad`, we call the `asyncAfter` method on the `DispatchQueue.main` queue, which trigger a calculation of the current disk cache size there. This value indicates the disk space taken by Kingfisher as the disk cache.
|
|
|
+
|
|
|
+ @Code(name: "ViewController.swift", file: 01-ViewController-11.swift)
|
|
|
+ }
|
|
|
+ @Step {
|
|
|
+ To make it clear, we can create an alert and display it to the user, with a button to clear the cache manually.
|
|
|
+ @Code(name: "ViewController.swift", file: 01-ViewController-12.swift) {
|
|
|
+ @Image(source:preview-5.png, alt:"An alert which shows the disk cache size used by Kingfisher, with a button to purge the cache.")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @Step {
|
|
|
+ Finally, call `clearCache` to purge both the memory cache and the disk cache. Then, if we try to reload the data of the table view, we can see the images are downloaded again from the network: in this case, "Image loaded from cache: none" will be printed to the console.
|
|
|
+ @Code(name: "ViewController.swift", file: 01-ViewController-13.swift)
|
|
|
+ The cache cleaning is only for demonstration purpose. In practice, usually you do not need to call it yourself. Kingfisher will manage and purge the data based on its default policy.
|
|
|
}
|
|
|
}
|
|
|
}
|