Swiftui 图像集框架

Swiftui 图像集框架,swiftui,Swiftui,在SwiftUI的官方教程中,我尝试自定义图像以显示整个屏幕 解决方案是将框架设置为固定的宽度和高度 struct CircleImage : View { var body: some View { Image("image01") // .frame(width: 300, height: 300) .clipShape(Circle()) .overlay( Cir

在SwiftUI的官方教程中,我尝试自定义图像以显示整个屏幕

解决方案是将框架设置为固定的宽度和高度

struct CircleImage : View {
    var body: some View {
        Image("image01")
//            .frame(width: 300, height: 300)
            .clipShape(Circle())
            .overlay(
                Circle().stroke(Color.white, lineWidth: 4))
            .shadow(radius: 10)   
    }
}
为什么ContentView调用.frame(宽度:300,高度:300)无效?

我假设当你说“无效”时,你的意思是图像没有调整到宽度和高度为300的帧的大小。如果是这样,您的问题是您无法调整图像的大小。将
CircleImage
更新为下面的代码,图像应调整大小

struct CircleImage : View {
    var body: some View {
        Image("image01")
            .resizable() //add this line
            .clipShape(Circle())
            .overlay(
                Circle().stroke(Color.white, lineWidth: 4))
            .shadow(radius: 10)   
    }
}
你说的“无效”是什么意思?图像边框是否未设置为300x300?如果是这样的话,那是意料之中的事。
struct CircleImage : View {
    var body: some View {
        Image("image01")
            .resizable() //add this line
            .clipShape(Circle())
            .overlay(
                Circle().stroke(Color.white, lineWidth: 4))
            .shadow(radius: 10)   
    }
}