2019-08-07 18:10:05 +08:00
|
|
|
# SDWebImageSwiftUI
|
|
|
|
|
2019-08-09 16:45:40 +08:00
|
|
|
[![CI Status](https://travis-ci.com/dreampiggy/SDWebImageSwiftUI.svg?branch=master)](https://travis-ci.com/dreampiggy/SDWebImageSwiftUI)
|
2019-08-07 18:10:05 +08:00
|
|
|
[![Version](https://img.shields.io/cocoapods/v/SDWebImageSwiftUI.svg?style=flat)](https://cocoapods.org/pods/SDWebImageSwiftUI)
|
|
|
|
[![License](https://img.shields.io/cocoapods/l/SDWebImageSwiftUI.svg?style=flat)](https://cocoapods.org/pods/SDWebImageSwiftUI)
|
|
|
|
[![Platform](https://img.shields.io/cocoapods/p/SDWebImageSwiftUI.svg?style=flat)](https://cocoapods.org/pods/SDWebImageSwiftUI)
|
2019-08-09 16:28:54 +08:00
|
|
|
[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
|
|
|
|
[![SwiftPM compatible](https://img.shields.io/badge/SwiftPM-Compatible-brightgreen.svg)](https://swift.org/package-manager/)
|
2019-08-07 18:10:05 +08:00
|
|
|
|
2019-08-07 18:51:28 +08:00
|
|
|
## What's for
|
2019-08-07 18:10:05 +08:00
|
|
|
|
2019-08-07 18:51:28 +08:00
|
|
|
This is an experimental project for [SDWebImage](https://github.com/SDWebImage/SDWebImage).
|
|
|
|
|
|
|
|
It aims to ensure the following function available for users and try to do some experiences for Swift platform.
|
|
|
|
|
|
|
|
+ Swift Package Manager integration
|
|
|
|
+ SwiftUI compatibility
|
|
|
|
+ Swift source code compatibility
|
2019-08-07 18:10:05 +08:00
|
|
|
|
|
|
|
## Requirements
|
|
|
|
|
2019-08-07 18:51:28 +08:00
|
|
|
+ Xcode 11+
|
|
|
|
+ iOS 13+
|
|
|
|
+ macOS 10.15+
|
|
|
|
+ tvOS 13+
|
|
|
|
+ watchOS 6+
|
|
|
|
|
2019-08-07 18:10:05 +08:00
|
|
|
## Installation
|
|
|
|
|
2019-08-09 16:15:44 +08:00
|
|
|
#### CocoaPods
|
|
|
|
|
2019-08-07 18:10:05 +08:00
|
|
|
SDWebImageSwiftUI is available through [CocoaPods](https://cocoapods.org). To install
|
|
|
|
it, simply add the following line to your Podfile:
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
pod 'SDWebImageSwiftUI'
|
|
|
|
```
|
|
|
|
|
2019-08-09 16:15:44 +08:00
|
|
|
#### Carthage
|
|
|
|
|
|
|
|
SDWebImageSwiftUI is available through [Carthage](https://github.com/Carthage/Carthage).
|
|
|
|
|
|
|
|
```
|
|
|
|
github "dreampiggy/SDWebImageSwiftUI"
|
|
|
|
```
|
|
|
|
|
|
|
|
#### Swift Package Manager
|
|
|
|
|
|
|
|
SDWebImageSwiftUI is available through [Swift Package Manager](https://swift.org/package-manager/).
|
|
|
|
|
|
|
|
```swift
|
|
|
|
let package = Package(
|
|
|
|
dependencies: [
|
|
|
|
.package(url: "https://github.com/dreampiggy/SDWebImageSwiftUI.git", .branch("master"))
|
|
|
|
],
|
|
|
|
)
|
|
|
|
```
|
|
|
|
|
2019-08-07 18:51:28 +08:00
|
|
|
## Usage
|
|
|
|
|
|
|
|
+ Using `WebImage` to load network image
|
|
|
|
|
|
|
|
It supports the placeholder and detail options control for image loading as SDWebImage.
|
|
|
|
|
|
|
|
```swift
|
|
|
|
var body: some View {
|
|
|
|
WebImage(url: URL(string: "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic")!)
|
|
|
|
.scaledToFit()
|
|
|
|
.frame(width: 300, height: 300, alignment: .center)
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
+ Using `AnimatedImage` to play animation
|
|
|
|
|
|
|
|
```swift
|
|
|
|
var body: some View {
|
|
|
|
AnimatedImage(url: URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif")!)
|
2019-08-09 16:15:44 +08:00
|
|
|
AnimatedImage(data: try! Data(contentsOf: URL(fileURLWithPath: "/tmp/foo.webp")))
|
2019-08-07 18:51:28 +08:00
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
It supports both image url or image data for animated image format.
|
|
|
|
|
|
|
|
## Demo
|
|
|
|
|
|
|
|
To run the example using SwiftUI, following the steps:
|
|
|
|
|
|
|
|
```
|
|
|
|
cd Example
|
|
|
|
pod install
|
|
|
|
```
|
|
|
|
|
|
|
|
Then open the Xcode Workspace to run the demo application.
|
|
|
|
|
|
|
|
## Screenshot
|
|
|
|
|
|
|
|
![](Example/Screenshot/1.jpg)
|
|
|
|
|
2019-08-07 18:10:05 +08:00
|
|
|
## Author
|
|
|
|
|
2019-08-07 18:51:28 +08:00
|
|
|
DreamPiggy
|
2019-08-07 18:10:05 +08:00
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
SDWebImageSwiftUI is available under the MIT license. See the LICENSE file for more info.
|
2019-08-07 18:51:28 +08:00
|
|
|
|
|
|
|
|