๐view.watermark()
swiftโฉ custom โฉ extension โฉ View โฉ modifier โฉ .watermark()
โฌ๏ธ ้่ฆ๏ผ .nsfw(), Image(playground:)
struct ContentView: View {
// picker selection
@State private var selection = "bottom right"
// watermark alignment
@State private var alignment: Alignment = .bottomTrailing
var body: some View {
VStack {
alignmentPicker
blocks
}.frame(height: 300)
}
var blocks: some View {
HStack {
ZStack {
Color.gray
Image(playground: "slot_09@2x.png") // ๐ Image
}
.watermark{ Label("watermark", systemImage: "pin") }
.nsfw() // ๐ .nsfw
Color.gray
// โญ๏ธ watermark with alignment
.watermark(alignment){ Text("๐ hello") }
}
}
// โญ๏ธ alignments for watermarks
let alignments: [String: Alignment] = [
"top left" : .topLeading,
"top right" : .topTrailing,
"bottom right": .bottomTrailing,
"bottom left" : .bottomLeading
]
// โญ๏ธ picker content
let keys = ["bottom right", "bottom left", "top left", "top right"]
/// segmented control
var alignmentPicker: some View {
Picker("Alignment", selection: $selection) {
ForEach(0..<keys.count){ Text(keys[$0]).tag(keys[$0]) }
}
.pickerStyle(.segmented)
.shadow(radius: 2)
.padding()
// โญ๏ธ animate the change when `selection` changes
.onChange(of: selection) { newSelection in
withAnimation {
self.alignment = alignments[newSelection]!
}
}
}
}
Last updated
Was this helpful?