Kun*_*rma 6 shapes ios swift swiftui swiftui-environment
在 SwiftUI Shapes 中,我们可以使用渐变来制作不同的颜色描边。
例如-
@ViewBuilder
func lineWithSecondColorStyleFromPositionN() -> some View {
let n = 0.5
GeometryReader { gr in
Path { path in
path.move(to: CGPoint(x: 0, y: 0))
path.addLine(to: CGPoint(x: gr.size.width, y: gr.size.height))
}
.stroke(
LinearGradient(stops: [
Gradient.Stop(color: .red, location: 0),
Gradient.Stop(color: .red, location: n),
Gradient.Stop(color: .blue, location: n),
Gradient.Stop(color: .blue, location: 1)
], startPoint: .top, endPoint: .bottom),
style: StrokeStyle(lineWidth: 10, lineCap: .butt)
)
}
.frame(height: 200)
}
Run Code Online (Sandbox Code Playgroud)
是否可以通过任何方式对笔划样式执行相同的操作?
创建这样的东西 -
笔划样式 1(实线)从 0 到n,
描边样式 2(虚线)从n到 1。
哪里n可以是任意浮点数0<=n<=1
| 归档时间: |
|
| 查看次数: |
961 次 |
| 最近记录: |