-
-
Save NickG-DK/860af99598f9fdee002f5385168b30c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
@State var showActionSheet = false | |
@State var showImagePicker = false | |
@State var sourceType:UIImagePickerController.SourceType = .camera | |
@State var image:UIImage? | |
var body: some View { | |
VStack { | |
if image != nil { | |
Image(uiImage: image!) | |
.resizable() | |
.scaledToFit() | |
.frame(width:150, height:150) | |
} else { | |
Image(systemName: "person") | |
.resizable() | |
.scaledToFit() | |
.frame(width:150, height:150) | |
} | |
Button(action: { | |
self.showActionSheet = true | |
}) { | |
Text("Show Image Picker") | |
}.actionSheet(isPresented: $showActionSheet){ | |
ActionSheet(title: Text("Add a picture to your post"), message: nil, buttons: [ | |
//Button1 | |
.default(Text("Camera"), action: { | |
self.showImagePicker = true | |
self.sourceType = .camera | |
}), | |
//Button2 | |
.default(Text("Photo Library"), action: { | |
self.showImagePicker = true | |
self.sourceType = .photoLibrary | |
}), | |
//Button3 | |
.cancel() | |
]) | |
}.sheet(isPresented: $showImagePicker){ | |
imagePicker(image: self.$image, showImagePicker: self.$showImagePicker, sourceType: self.sourceType) | |
} | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment