Kingfisher简单使用

Kingfisher简单使用

========================

UIKit

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
let url = dataShare.queryFromManyTable(with: modelName, from: [dataShare.cuturalRelicsIntroduction,
dataShare.models3DIntroduction,
dataShare.paintingModelsIntroduction])?.image
objectImageView.kf.indicatorType = .activity
objectImageView.kf.setImage(with: URL(string: url))
// 设置超时时间
let downloader = KingfisherManager.shared.downloader
// 超时时间(秒)
downloader.downloadTimeout = 50

// 获取缓存代销
let cache = KingfisherManager.shared.cache
// 设置最大缓存为多少 100M 默认是无上限
cache.memoryStorage.config.totalCostLimit = 100 * 1024 * 1024
// 设置保存时间 1天 默认5分钟
cache.memoryStorage.config.expiration = StorageExpiration.seconds(300)
cache.diskStorage.config.sizeLimit = 100 * 1024 * 1024
cache.diskStorage.config.expiration = StorageExpiration.days(7)

SwiftUI

1
2
3
4
5
6
KFImage(URL(string: Images.help.url))
.diskCacheExpiration(.days(365))
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(.white)
.frame(width: 20.fitCGWidth, height: 20.fitCGWidth, alignment: .center)

本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!