Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xaoxuu/imagefetchable
图片拉取协议,使组件库可以不依赖具体的网络库
https://github.com/xaoxuu/imagefetchable
Last synced: 29 days ago
JSON representation
图片拉取协议,使组件库可以不依赖具体的网络库
- Host: GitHub
- URL: https://github.com/xaoxuu/imagefetchable
- Owner: xaoxuu
- License: mit
- Created: 2024-07-16T10:47:02.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-07-31T10:10:43.000Z (3 months ago)
- Last Synced: 2024-07-31T10:57:37.370Z (3 months ago)
- Language: Swift
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ImageFetchable
图片拉取协议,使组件库可以不依赖具体的网络库
组件库中这样设置图片:
```swift
// ---- UIImageView ----
// 设置网络图片(字符串)
await imgv.fetcher.setImage(imageURLStr)
// 设置网络图片(URL)
await imgv.fetcher.setImage(URL(string: imageURLStr))
// 设置本地图片(和网络图片用法一致)
await imgv.fetcher.setImage(imageName)// ---- UIButton ----
// 设置网络图片(字符串)
await btn.fetcher?.setImage(imageURLStr, for: .highlighted)
// 设置网络图片(字符串,可不传 state 默认设为 normal)
await btn.fetcher?.setImage(imageURLStr)
// 设置网络图片(URL)
await btn.fetcher?.setImage(URL(string: imageURLStr))// 语法糖:省略 .fetcher 的写法
await imgv.setImage(urlStringOrImageName)
await btn.setImage(urlStringOrImageName)
```集成组件的工程实现协议:
```swift
import ImageFetchable
import 任意网络库工具extension ImageFetchable: ImageFetchable_UIImageView {
public func fetchImage(_ imageView: UIImageView, imageName: String?) async -> Result {
<#code#>
}
public func fetchImage(_ imageView: UIImageView, imageURL: URL?, placeholder: UIImage?) async -> Result {
<#code#>
}
}extension ImageFetchable: ImageFetchable_UIButton {
public func fetchButtonImage(_ button: UIButton, imageName: String?, for state: UIControl.State) async -> Result {
<#code#>
}
public func fetchButtonImage(_ button: UIButton, imageURL: URL?, placeholder: UIImage?, for state: UIControl.State) async -> Result {
<#code#>
}
}
```