PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 29, 2022

[FIXED] How to resize image in swift picker menu style

 July 29, 2022     image, picker, svg, swift, swiftui     No comments   

Issue

I want to use a image beside some text in my picker, but image is scaled up and I can't resize it with .resizable .frame and ... . How can i fix this problem? I use both svg and png format and neither of those don't working properly.

I using image from asset

here is the screen shot and its ok when I tapped on it

struct ContentView: View {
    @State var array = ["one", "two", "three", "four"]
    @State var selection: String = "one"
    var body: some View {
        HStack {
            Picker("Select",selection: $selection) {
                ForEach(array, id: \.self) { item in
                    HStack {
                        Text(item)
                            Image("BTC")
                                .resizable()
                                .clipped()
                    }
                   
                }
            }
            .pickerStyle(.menu)
            .padding(.trailing)
            
        }
        
    }
}

Solution

You can use Menu for this purpose:

struct ContentView: View {
    @State var array = ["one", "two", "three", "four"]
    @State var selection: String = "one"
    var body: some View {
        Menu(content: {
            Picker("Select",selection: $selection) {
                            ForEach(array, id: \.self) { item in
                                HStack {
                                    Text(item)
                                    Image("BTC")
                                }
                               
                            }
                        }
        }, label: {
            Text(selection)
        })
    }
}


Answered By - Kush Bhavsar
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing