Skip to content

Instantly share code, notes, and snippets.

@garethpaul
Created January 20, 2020 05:28
Show Gist options
  • Select an option

  • Save garethpaul/00fe0384cef0a07bb43267a503a0038f to your computer and use it in GitHub Desktop.

Select an option

Save garethpaul/00fe0384cef0a07bb43267a503a0038f to your computer and use it in GitHub Desktop.
//
// IconView.swift
// FSQNearby
//
// Created by GPJ on 1/19/20.
// Copyright © 2020 GPJ. All rights reserved.
//
import SwiftUI
struct IconView: View {
@ObservedObject var imageLoader:ImageLoader
@State var image:UIImage = UIImage()
init(withURL url:String) {
imageLoader = ImageLoader(urlString:url)
}
var body: some View {
VStack {
Image(uiImage: image)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width:30, height:30)
}.onReceive(imageLoader.didChange) { data in
self.image = UIImage(data: data) ?? UIImage()
}.background(Color.black)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment