.watermark()

SwiftUI โŸฉ Views โŸฉ View Modifiers โŸฉ examples โŸฉ

โฌ†๏ธ ้œ€่ฆ๏ผš .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