0

当我尝试更改 MGLPolyline 的颜色时,应用程序崩溃并打印出这个致命错误(它也需要我:

断言失败:(r_ <= 1.0f),函数 Color,文件 /Users/distiller/project/include/mbgl/util/color.hpp,第 18 行。

我正在使用 Mapbox。这是我用来更改颜色的代码:

//Colors:
let orangeColor = UIColor(red: 253, green: 70, blue: 2, alpha: 100)
let purpleColor = UIColor(red: 101, green: 0, blue: 141, alpha: 100)
let redColor = UIColor(red: 254, green: 0, blue: 0, alpha: 100)
let pinkPurpColor = UIColor(red: 193, green: 6, blue: 245, alpha: 100)
let pinkColor2 = UIColor(red: 254, green: 0, blue: 131, alpha: 100)

func mapView(_ mapView: MGLMapView, strokeColorForShapeAnnotation annotation: MGLShape) -> UIColor {

    let arrayOfColors = [pinkColor2, pinkPurpColor, redColor, purpleColor, orangeColor]

    let randomIndex = Int(arc4random_uniform(UInt32(arrayOfColors.count)))

    return arrayOfColors[randomIndex]
}
4

1 回答 1

0

值 < 1 和除法 255。

斯威夫特 4.2

你能试试这个代码吗

let orangeColor = UIColor(red: 253/255, green: 70/255, blue: 2/255, alpha: 1)
于 2019-02-09T19:52:36.207 回答