๐ดStroke
.stroke(lineWidth:) ๆ .stroke(style:) ๆๆๅฏฆๅฟๅๅฝข่ฎๆใ็ฉบๅฟ็ใ๏ผๅช็ไธใ้็ทใๆฏๅฏฆๅฟ็ใ( ๐ ๐็ฏไพ )
โ ๏ธ ๆณจๆ๏ผ
โข .stroke(lineWidth:), .stroke(style:) ๅๅณ็ไพ็ถๆฏๅ Shapeใ
โข .stroke(_:lineWidth:), .stroke(_:style:) ๅๅณๅปๆฏ View๏ผ่ฆๆณจๆโ๏ธ
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())
// outline
.overlay(
RoundedRectangle(cornerRadius: 30, style: .continuous)
.stroke()
)
// dash line
.stroke(.black, style: .init(
lineWidth : 5,
lineCap : .round,
lineJoin : .round,
miterLimit: .infinity,
dash : [100, 20],
dashPhase : 10
))
// stroke gradient
.stroke(.linearGradient(
colors : [.white.opacity(0.3), .black.opacity(0.1)],
startPoint: .top,
endPoint : .bottom
)
SwiftOnTap
Path โฉ strokedPath(_:) โ Path
InsettableShape โฉ strokeBorder(_:style:antialiased:) โ some View.
SwiftUI โฉ Shapes โฉ
InsettableShape โฉ
strokeBorder(_:style:antialiased:) - โญ๏ธ ๆณจๆ๏ผๆญค็ณปๅ้ฝๆฏๅๅณ some View.
Shape โฉ
stroke(lineWidth:) โ some Shape
stroke(style:) โ some Shape
stroke(_:lineWidth:) โ some View (stroke with a
ShapeStyle
).stroke(_:style:) โ some View.
Design+Code โฉ Shape, Stroke and Blend Mode
Last updated