目录
目录README.md

SwiftUI GIF

Lightweight SwiftUI component for rendering GIFs from data or assets, with no external dependencies. As a bonus, there’s an extension that loads GIFs into UIImages, as well as a UIKIt-compatible UIGIFImage class.

Preview

Installation

This component is distributed as a Swift package.

Sample usage

import SwiftUIGIF

struct GIFImageTest: View {
    @State private var imageData: Data? = nil
    
    var body: some View {
        VStack {
            GIFImage(name: "preview") // load from assets
                .frame(height: 300)
            if let data = imageData {
                GIFImage(data: data) // load from data
                    .frame(width: 300)
            } else {
                Text("Loading...")
                    .onAppear(perform: loadData)
            }
        }
    }
    
    private func loadData() {
        let task = URLSession.shared.dataTask(with: URL(string: "https://github.com/globulus/swiftui-webview/raw/main/Images/preview_macos.gif?raw=true")!) { data, response, error in
            imageData = data
        }
        task.resume()
    }
}

Recipe

For a more detailed description of the code, visit this recipe. Check out SwiftUIRecipes.com for more SwiftUI recipes!

关于
299.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号