swiftui 裁剪未裁剪图像

swiftui clipped not cut image

您好,我在 SwiftUi 中遇到图像问题,我的布局如下:

图片和健身是可以点击的,但是当我点击健身时打开图片页面。

这是我的代码:

VStack {
    HStack(alignment: .center) {
        NavigationLink(destination: FullNewsListView(category: "Fitness")) {
            Text("Fitness")
                .foregroundColor(Color("#29B1B3"))
                .font(Font.custom("AvenirNextLTPro-Bold", size: 20))
            Image("forward_blue")
        }
        Spacer()
        }
    .padding(.bottom, 10)
    VStack(alignment: .leading, spacing: 10) {
        HStack {
            URLImage(URL(string: "http://myPhoto")!) { proxy in
                proxy.image
                    .renderingMode(.original)
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .frame(minWidth: 0, maxWidth: .infinity)
                    .frame(height: 180)
                    .cornerRadius(12)
                    .clipped()

            }

        }
        HStack {
            Text(api.newsFitnessHome.news!.title)
                .foregroundColor(.black)
                .font(Font.custom("AvenirNextLTPro-Demi", size: 15))
                .opacity(0.8)
                .lineSpacing(5)
                .lineLimit(2)
                .fixedSize(horizontal: false, vertical: true)
            Spacer()
        }
    }
}
.padding(.horizontal, 30)

你能试试这个设置吗:

        VStack {
            HStack(alignment: .center) {
                NavigationLink(destination: FullNewsListView(category: "Fitness")) {
                    HStack {
                        Text("Fitness")
                            //   .foregroundColor(Color("#29B1B3"))
                            .font(Font.custom("AvenirNextLTPro-Bold", size: 20))
                        Image("forward_blue")
                        Spacer()
                    }
                }
                Spacer()
            }.padding(.bottom, 10)
        }

....

另外 .foregroundColor(Color("#29B1B3")) 对我不起作用。

无法测试,因为没有所有可用的组件,但我想这是由于图像命中区域,请参见下面的一些假设

URLImage(URL(string: "http://myPhoto")!) { proxy in
    proxy.image
        .renderingMode(.original)
        .resizable()
        .aspectRatio(contentMode: .fill)
        .frame(minWidth: 0, maxWidth: .infinity)
        .frame(height: 180)
        .cornerRadius(12)
        .clipped()
        .contentShape(Rectangle())      // try this
}
//.contentShape(Rectangle())      // or here