is it possible to develop a custom view for Retake/UsePhoto view?
Here is the screen of needed component:
https://i.sstatic.net/jtGZ7fhF.png
This preview appears immediately after the photo is taken. I can either reject the photo or use the photo I took.
I need to change the design of this one: replace the buttons with other buttons, add a text box. How can I do this using standard code?
Here is my code:
struct ImagePicker: UIViewControllerRepresentable {
@Environment(\.presentationMode) private var presentationMode
@Binding var state: PhotoViewModel.ImageState
@Binding var selectedImage: UIImage?
let sourceType: UIImagePickerController.SourceType
init(selectedImage: Binding, sourceType: UIImagePickerController.SourceType) {
self._state = .constant(.none)
self._selectedImage = selectedImage
self.sourceType = sourceType
}
init(state: Binding, sourceType: UIImagePickerController.SourceType) {
self._selectedImage = .constant(nil)
self._state = state
self.sourceType = sourceType
}
func makeUIViewController(context: Context) -> UIImagePickerController {
let picker = UIImagePickerController()
picker.sourceType = sourceType
if sourceType == .camera {
picker.cameraDevice = .rear
}
picker.delegate = context.coordinator
picker.allowsEditing = false
return picker
}
func updateUIViewController(_ uiViewController: UIImagePickerController, context: Context) {}
func makeCoordinator() -> Coordinator {
Coordinator(self)
}
class Coordinator: NSObject, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
let parent: ImagePicker
init(_ parent: ImagePicker) {
self.parent = parent
}
func imagePickerController(
_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]
) {
if let uiImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
parent.state = .picked(uiImage)
parent.selectedImage = uiImage
parent.presentationMode.wrappedValue.dismiss()
}
}
}
}
Discover more from TrendyShopToBuy
Subscribe to get the latest posts sent to your email.