如何用图像填充路径?

时间:2020-01-02 10:05:09

标签: swift swiftui

给出以下GeometryReader(...)

GeometryReader { geo in
            Path  { path in
                let width = geo.size.width
                let height = geo.size.height * 0.40
                let litheight = geo.size.height * 0.24
                path.addLines([
                    CGPoint(x: 0, y: litheight),
                    CGPoint(x: width, y: height ),
                    CGPoint(x: width, y: 0),
                    CGPoint(x: 0, y: 0)
                ])
            }
        }.edgesIgnoringSafeArea(.top)

我想用背景图像设置顶部区域。

除了不完全符合我的要求,我尝试了以下操作:

        GeometryReader { geo in
            Path  { path in
                let width = geo.size.width
                let height = geo.size.height * 0.40
                let litheight = geo.size.height * 0.24
                path.addLines([
                    CGPoint(x: 0, y: litheight),
                    CGPoint(x: width, y: height ),
                    CGPoint(x: width, y: 0),
                    CGPoint(x: 0, y: 0)
                ])
            }

            Image(systemName: "faceid")
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: geo.size.width, height: geo.size.height, alignment: .bottomTrailing)
        }
        .edgesIgnoringSafeArea(.top)

这是结果:

enter image description here

这就是我想要实现的:

enter image description here

0 个答案:

没有答案