Created
July 14, 2021 17:13
-
-
Save emin-grbo/8bb4410a763e6fe22c98c48377cbf918 to your computer and use it in GitHub Desktop.
SwiftUI Blend modes Preview
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct Blender: Identifiable { | |
let id = UUID() | |
let mode: BlendMode | |
let name: String | |
} | |
struct BlendModes: View { | |
var body: some View { | |
let blendModes = [ | |
Blender(mode: .normal, name: "normal"), | |
Blender(mode: .multiply, name: "multiply"), | |
Blender(mode: .screen, name: "screen"), | |
Blender(mode: .overlay, name: "overlay"), | |
Blender(mode: .darken, name: "darken"), | |
Blender(mode: .lighten, name: "lighten"), | |
Blender(mode: .colorDodge, name: "colorDodge"), | |
Blender(mode: .colorBurn, name: "colorBurn"), | |
Blender(mode: .softLight, name: "softLight"), | |
Blender(mode: .hardLight, name: "hardLight"), | |
Blender(mode: .difference, name: "difference"), | |
Blender(mode: .exclusion, name: "exclusion"), | |
Blender(mode: .hue, name: "hue"), | |
Blender(mode: .saturation, name: "saturation"), | |
Blender(mode: .color, name: "color"), | |
Blender(mode: .luminosity, name: "luminosity"), | |
Blender(mode: .sourceAtop, name: "sourceAtop"), | |
Blender(mode: .destinationOver, name: "destinationOver"), | |
Blender(mode: .destinationOut, name: "destinationOut"), | |
Blender(mode: .plusDarker, name: "plusDarker"), | |
Blender(mode: .plusLighter, name: "plusLighter"), | |
] | |
let columns = [ | |
GridItem(), | |
GridItem(), | |
GridItem(), | |
GridItem()] | |
ZStack { | |
Color.xpurple | |
ScrollView { | |
LazyVGrid(columns: columns) { | |
ForEach(blendModes) { item in | |
VStack { | |
Image("badge_5") | |
.blendMode(item.mode) | |
Text(item.name) | |
.foregroundColor(.white) | |
} | |
} | |
} | |
.padding(.top, 60) | |
} | |
} | |
.edgesIgnoringSafeArea(.all) | |
} | |
} | |
struct BlendModes_Previews: PreviewProvider { | |
static var previews: some View { | |
BlendModes() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment