Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I change image size in Swift UI [duplicate]

Tags:

swift

swiftui

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

like image 292
Por Avatar asked Nov 02 '25 04:11

Por


2 Answers

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

like image 176
Joe Avatar answered Nov 04 '25 03:11

Joe


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()
like image 21
Rohit Makwana Avatar answered Nov 04 '25 01:11

Rohit Makwana



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!