swiftui中是否有类似于UIKit UIView的视图
swiftui中有一个有EmptyView
没有人知道这个视图是做什么的
Image("image")
.resizable()
.aspectRatio(3/2, contentMode: .fill)
这弄乱了图像是否有其他方法可以调整图像大小
在 SwiftUI 中,Color、Text、Image 等原始视图的行为类似于 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("image name")
.resizable()
.scaledToFit()
有关图像的更多自定义,请查看以下链接 https://developer.apple.com/documentation/swiftui/image/3269652-frame
希望对你有帮助!!