Skip to content

Instantly share code, notes, and snippets.

@sturdysturge
Last active November 15, 2022 01:55
Show Gist options
  • Select an option

  • Save sturdysturge/ca0cf209ea47dbf6290ecfbe3ba83d31 to your computer and use it in GitHub Desktop.

Select an option

Save sturdysturge/ca0cf209ea47dbf6290ecfbe3ba83d31 to your computer and use it in GitHub Desktop.
import SwiftUI
extension BlendMode: Identifiable, CaseIterable {
public var id: Self { self }
public static var allCases: [BlendMode] {
[.color, .colorBurn, .colorDodge,
.darken, .destinationOut, .destinationOver,
.difference, .exclusion, .hardLight,
.hue, .lighten, .luminosity,
.multiply, .normal, .overlay,
.plusDarker, .plusLighter, .saturation,
.screen, .softLight, .sourceAtop]
}
}
struct ContentView: View {
@State var blendMode = BlendMode.color
var body: some View {
List {
Section("Blend Mode") {
Picker("", selection: $blendMode) {
ForEach(BlendMode.allCases) { mode in
Text(String(describing: mode))
}
}
}
Section("Demo") {
ZStack {
Text("View One")
.padding()
.background(Color.green)
.foregroundColor(.white)
.blendMode(blendMode)
Text("View Two")
.offset(x: 15, y: 15)
.padding()
.background(Color.blue)
.foregroundColor(.white)
.blendMode(blendMode)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment