๐Ÿ”นshape.stroke()

SwiftUI โŸฉ shapes โŸฉ transform โŸฉ .stroke()

.stroke(lineWidth:) ๆˆ– .stroke(style:) ๆœƒๆŠŠใ€Œๅฏฆๅฟƒๅœ–ๅฝข่ฎŠๆˆ็ฉบๅฟƒ็š„ใ€๏ผŒๅช็•™ไธ‹ใ€Œ้‚Š็ทšใ€ๆ˜ฏๅฏฆๅฟƒ็š„ใ€‚( ๐Ÿ‘‰ ๐Ÿ’ˆ็ฏ„ไพ‹ )

shape with strokes
import SwiftUI
import PlaygroundSupport

// content view
struct ContentView: View {
    
    let gradient = LinearGradient(
        gradient  : Gradient(colors: [.white, .yellow, .red]), 
        startPoint: .topLeading, 
        endPoint  : .bottomTrailing
    )
    
    let dashed = StrokeStyle(lineWidth: 3, dash:[8,4])
    let borderColor: Color = .gray
    
    // view body
    var body: some View {
        HStack {

            // โญ๏ธ stroke once
            ZStack {
                Circle()
                    .stroke(lineWidth:40)
                    .fill(gradient)
                Circle().stroke(style: dashed)
            }.border(borderColor)

            // โญ๏ธ stroke twice
            Circle()
                .stroke(lineWidth:40)
                .stroke(lineWidth: 20)
                .fill(gradient).border(borderColor).opacity(0.9)

            // โญ๏ธ stroke 3 times
            Circle()
                .stroke(lineWidth:40)
                .stroke(lineWidth: 20)
                .stroke(lineWidth: 10)
                .fill(gradient).border(borderColor).opacity(0.9)

        }.padding(50).frame(height:300)
    }
}

// live view
PlaygroundPage.current.setLiveView(ContentView())

Last updated

Was this helpful?