SwiftUI add inverted mask

前端 未结 5 1224
醉话见心
醉话见心 2020-12-15 22:53

I\'m trying to add a mask to two shapes such that the second shape masks out the first shape. If I do something like Circle().mask(Circle().offset(…)), this has

5条回答
  •  再見小時候
    2020-12-15 23:06

    If you are after something like this:

    Then you can just put the two shapes in a ZStack and give the masking one the color of a background:

    struct MaskView: View {
    
        @Environment(\.colorScheme) var colorScheme: ColorScheme
    
        var body: some View {
            ZStack {
                Circle()
                    .fill(Color.yellow)
                Circle()
                    .fill(colorScheme == .dark ? Color.black : Color.white)
                    .offset(x: 150.0, y: 10.0)
            }
        }
    }
    

提交回复
热议问题