SDWebImageSwiftUI, popüler SDWebImage kütüphanesinin SwiftUI ile entegre edilmiş bir sürümüdür. Bu kütüphane, resimleri hızlı ve etkili bir şekilde yüklemek, önbelleğe almak ve göstermek için tasarlanmıştır. SDWebImage’in sunduğu güçlü özellikleri SwiftUI projelerinize entegre etmenizi sağlar.
SDWebImageSwiftUI kütüphanesini SwiftUI projenize entegre etmek oldukça basittir. İlk olarak, projenize bağımlılığı eklemek için Swift Package Manager’ı kullanabilirsiniz. Ardından, aşağıdaki örnekte olduğu gibi resimleri yüklemek ve göstermek için SDWebImageSwiftUI’yi kullanabilirsiniz:
var body: some View {
WebImage(url: URL(string: "https://nokiatech.github.io/heif/content/images/ski_jump_1440x960.heic")) { image in
image.resizable() // Control layout like SwiftUI.AsyncImage, you must use this modifier or the view will use the image bitmap size
} placeholder: {
Rectangle().foregroundColor(.gray)
}
// Supports options and context, like `.delayPlaceholder` to show placeholder only when error
.onSuccess { image, data, cacheType in
// Success
// Note: Data exist only when queried from disk cache or network. Use `.queryMemoryData` if you really need data
}
.indicator(.activity) // Activity Indicator
.transition(.fade(duration: 0.5)) // Fade Transition with duration
.scaledToFit()
.frame(width: 300, height: 300, alignment: .center)
}
Animasyonlu görüntüleri oynatmak için:
@State var isAnimating: Bool = true
var body: some View {
WebImage(url: URL(string: "https://raw.githubusercontent.com/liyong03/YLGIFImage/master/YLGIFImageDemo/YLGIFImageDemo/joy.gif"), isAnimating: $isAnimating)) // Animation Control, supports dynamic changes
// The initial value of binding should be true
.customLoopCount(1) // Custom loop count
.playbackRate(2.0) // Playback speed rate
.playbackMode(.bounce) // Playback normally to the end, then reversely back to the start
// `WebImage` supports advanced control just like `AnimatedImage`, but without the progressive animation support
}
Örnek Proje İçin: Github