像 UIKit UIView 这样的 SwiftUI 视图,如何更改图像的大小

SwiftUI view like UIKit UIView, How to change the size of the image

swiftui有没有类似UIKit UIView的view

swiftui 中有一个 EmptyView 有谁知道这个视图的作用

        Image("image")
        .resizable()
        .aspectRatio(3/2, contentMode: .fill)

这把图片弄乱了有没有其他方法可以调整图片大小

在 SwiftUI 中,颜色、文本、图像等原始视图的行为类似于 UIView。要更改图像大小,您只需要给它一个框架并首先将其设置为 resizable()

struct ContentView : View {

    var body: some View {

         Image("your image name")
            .resizable()
            .frame(width: 300, height: 300)
    }
}

希望对您有所帮助。

在 SwiftUI 中,有两种方法可以改变图片大小

1) 使其可调整大小并为图像提供一些框架

   Image("image name")
      .resizable()
      .frame(width: 10, height: 10, alignment: .center)

2) 使其可调整大小并 scaleToFit 属性 以适应图像

   Image("image name")
      .resizable()
      .scaledToFit()

更多自定义图片请看下方link https://developer.apple.com/documentation/swiftui/image/3269652-frame

希望对您有所帮助!!