如何遮蔽视图区域

问题描述 投票:0回答:1

我正在寻找有关通过SwiftUI实现以下目标的最佳方法的建议。

我有一个带有红色圆角矩形角的视图,和一个子视图,它是一个偏移到父级底部的矩形蓝色框。 1

但是,我希望遮蔽第二个附图2中的阴影区域,使该区域显示为白色(即,删除蓝色阴影区域),并且不确定如何最好地做到这一点。

这是目前的代码:-

import SwiftUI
import Foundation

struct PupilCell : View {
    var body : some View {

        ZStack { 

            Rectangle().frame(height: 60.0, alignment: .bottom).foregroundColor(Color.blue).offset(x: 0.0, y: 50.0)
            RoundedRectangle(cornerRadius: 25, style: .continuous).stroke(lineWidth: 2.0).fill(Color.red)
        }
    }
}
view swiftui shapes masking
1个回答
0
投票

这里是可能的方法:

<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLnN0YWNrLmltZ3VyLmNvbS9RNUZNRS5wbmcifQ==” alt =“整流罩”“>

ZStack {

    Rectangle().frame(height: 60.0, alignment: .bottom).foregroundColor(Color.blue).offset(x: 0.0, y: 50.0)
    RoundedRectangle(cornerRadius: 25, style: .continuous).stroke(lineWidth: 2.0).fill(Color.red)
}.mask(RoundedRectangle(cornerRadius: 25, style: .continuous).fill(Color.black))
© www.soinside.com 2019 - 2024. All rights reserved.