ImagePicker for SwiftUI
set
import ImagePickerSwiftUI
@State var selectedImage: UIImage?
@State var showPicker: Bool = false
action
Button {
showPicker.toggle()
} label: {
Text("Show Image Picker")
}
show
.sheet(isPresented: $showPicker) {
ImagePickerSwiftUI(
selectedImage: $selectedImage,
sourceType: .camera, // or .photoLibrary
allowsEditing: true
)
}
Add Info.plist
<key>NSCameraUsageDescription</key>
<string>I'll use it to take pictures.</string>
that's all
.camera | .photoLibrary |
---|---|