我想创建一个时钟样式与新的GaugeStyle自iOS 16。你可以看到我的代码和预览在这篇文章中。我想画的3,6,9,12线(粗体黑色)。彩色线显示实际小时(这部分工作良好)。
Gauge(value: Double(hour.formatted(.number)) ?? 0, in: 0...24) {
Image(systemName: "gauge.medium")
.font(.system(size: 50.0))
} currentValueLabel: {
Text(Image(systemName: weatherModel.symbol ?? "xmark.icloud"))
}
.gaugeStyle(clockGaugeStyle())
与结构代码
struct clockGaugeStyle: GaugeStyle {
private var purpleGradient = LinearGradient(gradient: Gradient(colors: [ Color(red: 207/255, green: 150/255, blue: 207/255), Color(red: 107/255, green: 116/255, blue: 179/255) ]), startPoint: .trailing, endPoint: .leading)
func makeBody(configuration: Configuration) -> some View {
ZStack {
Circle()
.trim(from: 0, to: 0.75 * configuration.value)
.stroke(purpleGradient, lineWidth: 20)
.rotationEffect(.degrees(135))
Circle()
.trim(from: 0, to: 0.75)
.stroke(Color.black, style: StrokeStyle(lineWidth: 10, lineCap: .butt, lineJoin: .round, dash: [1, 96], dashPhase: 0.0))
.rotationEffect(.degrees(360))
VStack {
configuration.currentValueLabel
.font(.system(size: 80, weight: .bold, design: .rounded))
.foregroundColor(.gray)
}
}
.frame(width: 300, height: 300)
}
}
2条答案
按热度按时间4ioopgfo1#
我知道你想在 Jmeter 上画出小时标记和3、6、9、12小时的显著标记。
这就是我的解决方案。如果大小总是固定的话,你就不需要
GeometryReader
了。wixjitnu2#
我会使用
Canvas
来绘制量规。它的代码更多,但我发现它更容易理解。下面是我的代码:即使您不使用
Canvas
,也应该考虑使用AngularGradient
而不是LinearGradient
。左边的图使用Angular 渐变。右边的图使用线性渐变。请注意,在左边,颜色从弧的起点到终点平滑地变化。在右边,请注意,弧左侧的大部分看起来都是粉红色,弧右侧的大部分看起来都是靛蓝色。线性渐变仅在大约10:30到1:30之间明显。
下面是我的代码(使用Angular 梯度):
线性梯度的唯一区别是如何初始化
Shading
: