show picker view content on tap of button or picker itself in swiftui?

Viewed 171

Unable to click on Image, picker is oopening ontap of Choose but not on drowDown image as shown in image.

enter image description here

I tried to place button too inplace of Image, but unable to acheive it. Below is the enum values:

enum ProfileRelationshipSignUp: String {
        case NONE = "Choose"
        case FATHER = "Father"
        case MOTHER = "Mother"
        case GUARDIAN = "Guardian"
        case RELATIVE = "Relative"
        case CHILD = "Child"
        case SIBLING = "Sibling"
        case COLLEAGUE = "Colleague"
        case SPOUSE = "Spouse"
    }
    

This is the view where picker and image is created

struct RelationShipView: View {

    @State var selectedRelationship: ProfileRelationshipSignUp = .NONE

    var body: some View {
        
        VStack {
            HStack {
                Picker(selection: $selectedRelationship, label: HStack(alignment: .top, spacing: 5) {
                    Text(microAppViewModel.users[indexValue].relationshipLabel)
                        .foregroundColor(.gray)
                        .font(Font.custom("Lato-Regular", size: valueSize))
                }, content: {
                    Text("Choose").tag(ProfileRelationshipSignUp.NONE)
                    Text("Mother").tag(ProfileRelationshipSignUp.MOTHER)
                    Text("Father").tag(ProfileRelationshipSignUp.FATHER)
                    Text("Guardian").tag(ProfileRelationshipSignUp.GUARDIAN)
                    Text("Relative").tag(ProfileRelationshipSignUp.RELATIVE)
                    Text("Child").tag(ProfileRelationshipSignUp.CHILD)
                    Text("Sibling").tag(ProfileRelationshipSignUp.SIBLING)
                    Text("Colleague").tag(ProfileRelationshipSignUp.COLLEAGUE)
                    Text("Spouse").tag(ProfileRelationshipSignUp.SPOUSE)
                })
                    .onChange(of: selectedRelationship, perform: { value in
                        switch(value) {
                        case .NONE: microAppViewModel.users[indexValue].relationshipLabel = "Choose"
                        case .FATHER: microAppViewModel.users[indexValue].relationshipLabel = "Father"
                        case .MOTHER: microAppViewModel.users[indexValue].relationshipLabel = "Mother"
                        case .GUARDIAN: microAppViewModel.users[indexValue].relationshipLabel = "Guardian"
                        case .RELATIVE: microAppViewModel.users[indexValue].relationshipLabel = "Relative"
                        case .CHILD: microAppViewModel.users[indexValue].relationshipLabel = "Child"
                        case .SIBLING: microAppViewModel.users[indexValue].relationshipLabel = "Sibling"
                        case .COLLEAGUE: microAppViewModel.users[indexValue].relationshipLabel = "Colleague"
                        case .SPOUSE: microAppViewModel.users[indexValue].relationshipLabel = "Spouse"
                        }
                    }).onAppear(perform: {
                        selectedRelationship = ProfileRelationshipSignUp(rawValue: microAppViewModel.users[indexValue].relationshipLabel) ?? .NONE
                    })
                    .pickerStyle(MenuPickerStyle())
                    .frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
                
                Image("DropDown")
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(width: 12, height: 12, alignment: .center)
                    .padding(.top, 5)
                
            }
            Divider()
                .frame(height: 1.0)
        }
    }
}
0 Answers
Related