3

Is the any ways to set image width and height sizes in swift ui. I found frame method but that is not what I want to.

Here is my swift file.

 import SwiftUI

struct HeaderBar: View {

    var body: some View {

        VStack(alignment: .center, spacing: 0.0) {

            HStack(alignment: .center) {
                Spacer()
                Image("jojologo-yellow")
                .frame(width: 30.0, height: 30.0) //that is not the solution to change image size
                .padding()
                Spacer()
            }
            .background(Color.orange)
            Spacer()

        }

    }
}

struct HeaderBar_Previews: PreviewProvider {
    static var previews: some View {
        HeaderBar()
    }
}

That would be great if I could use resize method in Image. For example

Image("jojologo-yellow").size(width: 30.0, height: 30.0)

So, my question is "Is there any ways to resize on image in swift ui

Por
  • 403
  • 5
  • 18

2 Answers2

9

Maybe Image("jojologo-yellow").resizable().frame(width: 30.0, height: 30.0) is what you are looking for?

Joe
  • 3,664
  • 25
  • 27
5

Add .resizable() modifier to your code

  Image("yourImageName")
    .resizable()
    .scaledToFill() // add if you need
    .frame(width: 30.0, height: 30.0) // as per your requirement
    .clipped()
Rohit Makwana
  • 4,337
  • 1
  • 21
  • 29