parent
78c8260d91
commit
8f78239046
@ -0,0 +1,51 @@
|
|||||||
|
//
|
||||||
|
// ImagePicker.swift
|
||||||
|
// DouShouQiIOS
|
||||||
|
//
|
||||||
|
// Created by Pierre FERREIRA on 17/06/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct ImagePicker: UIViewControllerRepresentable {
|
||||||
|
@Environment(\.presentationMode) private var presentationMode
|
||||||
|
var sourceType: UIImagePickerController.SourceType = .photoLibrary
|
||||||
|
@Binding var selectedImage: UIImage
|
||||||
|
|
||||||
|
func makeUIViewController(context: UIViewControllerRepresentableContext<ImagePicker>) -> UIImagePickerController {
|
||||||
|
|
||||||
|
let imagePicker = UIImagePickerController()
|
||||||
|
imagePicker.allowsEditing = false
|
||||||
|
imagePicker.sourceType = sourceType
|
||||||
|
imagePicker.delegate = context.coordinator
|
||||||
|
|
||||||
|
return imagePicker
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateUIViewController(_ uiViewController: UIImagePickerController, context: UIViewControllerRepresentableContext<ImagePicker>) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func makeCoordinator() -> Coordinator {
|
||||||
|
Coordinator(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
final class Coordinator: NSObject, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
|
||||||
|
|
||||||
|
var parent: ImagePicker
|
||||||
|
|
||||||
|
init(_ parent: ImagePicker) {
|
||||||
|
self.parent = parent
|
||||||
|
}
|
||||||
|
|
||||||
|
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
|
||||||
|
|
||||||
|
if let image = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
|
||||||
|
parent.selectedImage = image
|
||||||
|
}
|
||||||
|
|
||||||
|
parent.presentationMode.wrappedValue.dismiss()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,77 @@
|
|||||||
|
//
|
||||||
|
// PlayerSelect.swift
|
||||||
|
// DouShouQiIOS
|
||||||
|
//
|
||||||
|
// Created by Pierre FERREIRA on 17/06/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
struct PlayerSelect: View {
|
||||||
|
@State private var image = UIImage()
|
||||||
|
@State private var showSheet = false
|
||||||
|
|
||||||
|
|
||||||
|
var versus : Bool
|
||||||
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
Rectangle().fill(Color.bgColor).ignoresSafeArea()
|
||||||
|
VStack {
|
||||||
|
VStack{
|
||||||
|
Text("Joueur 1")
|
||||||
|
TextField("Entrez un nom ici",text: .constant(""))
|
||||||
|
}.foregroundStyle(.primary)
|
||||||
|
.padding(20)
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: 16)
|
||||||
|
.stroke(Color.player1, lineWidth: 5)
|
||||||
|
)
|
||||||
|
.padding(40)
|
||||||
|
|
||||||
|
if (versus){
|
||||||
|
|
||||||
|
VStack{
|
||||||
|
Text("Joueur 1")
|
||||||
|
|
||||||
|
HStack {
|
||||||
|
Image(uiImage: self.image)
|
||||||
|
.resizable()
|
||||||
|
.cornerRadius(50)
|
||||||
|
.frame(width: 100, height: 100)
|
||||||
|
.background(Color.black.opacity(0.2))
|
||||||
|
.aspectRatio(contentMode: .fill)
|
||||||
|
.clipShape(Circle())
|
||||||
|
|
||||||
|
ClassicTextDisplay(text: "Change photo")
|
||||||
|
.onTapGesture {
|
||||||
|
showSheet = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.padding(.horizontal, 20)
|
||||||
|
.sheet(isPresented: $showSheet) {
|
||||||
|
// Pick an image from the photo library:
|
||||||
|
ImagePicker(sourceType: .photoLibrary, selectedImage: self.$image)
|
||||||
|
|
||||||
|
// If you wish to take a photo from camera instead:
|
||||||
|
// ImagePicker(sourceType: .camera, selectedImage: self.$image)
|
||||||
|
}
|
||||||
|
|
||||||
|
TextField("Entrez un nom ici",text: .constant(""))
|
||||||
|
}.foregroundStyle(.primary)
|
||||||
|
.padding(20)
|
||||||
|
.overlay(
|
||||||
|
RoundedRectangle(cornerRadius: 16)
|
||||||
|
.stroke(Color.player2, lineWidth: 5)
|
||||||
|
)
|
||||||
|
.padding(40)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct PlayerSelect_Previews: PreviewProvider {
|
||||||
|
static var previews: some View {
|
||||||
|
PlayerSelect(versus: true)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue