ios - MGLPolyLine 颜色更改不起作用 - Swift 4、Mapbox

标签 ios swift swift4 mapbox mglmapview

当我尝试更改 MGLPolyline 的颜色时,应用程序崩溃并打印此 fatal error (它也需要我:

Assertion failed: (r_ <= 1.0f), function Color, file /Users/distiller/project/include/mbgl/util/color.hpp, line 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]
}

最佳答案

值 < 1 且除法 255。

swift 4.2

你能试试这个代码吗

let orangeColor = UIColor(red: 253/255, green: 70/255, blue: 2/255, alpha: 1)

关于ios - MGLPolyLine 颜色更改不起作用 - Swift 4、Mapbox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54610042/

相关文章:

ios - 相机闪光灯在 IOS 中使用 UIImagePickerController 自动/打开/关闭 - Swift

swift - 显示日期和时间

macos - Swift IBOutlets 在 awakeFromNib 中为零(xcode 6.1.1 osx 10.10.1)

swift4 - 来自字符串的 Swift Keypath

ios - Swift 在代码中将方向设置为特定屏幕

ios - NSURLConnection 在请求后几秒频繁超时

ios - xcode无法识别我的设备

ios - Google 签名会自动登录,也会在注销后立即登录。 swift 4

swift - 如何在 Swift 4.2 中的 Mapkit 上设置坐标轴

swift - swift 4 是否需要一个主类来运行?我什么时候应该使用类来运行我的代码?