根据WWDC视频梯度折线应该在SwiftUI map 视图中可用.
https://developer.apple.com/videos/play/wwdc2023/10043/?time=1360
let coordinates = [
CLLocationCoordinate2D(latitude: 37.7749, longitude: -122.4194),
CLLocationCoordinate2D(latitude: 37.3352, longitude: -122.0322),
CLLocationCoordinate2D(latitude: 34.0522, longitude: -118.2437)
]
let gradient = LinearGradient(colors: [.red, .green, .blue], startPoint: .leading, endPoint: .trailing)
let stroke = StrokeStyle(lineWidth: 5, lineCap: .round, lineJoin: .round, dash: [10, 10])
var body: some View {
Map {
MapPolyline(coordinates: coordinates)
.stroke(gradient, style: stroke)
}
}
似乎使用渐变的给定 colored颜色 中的第一种 colored颜色 来渲染整个多段线.这是一个错误吗/有没有其他方法来实现这一点?