Swift UIColor initializer - compiler error only when targeting iPhone5s

前端 未结 2 1307
旧巷少年郎
旧巷少年郎 2020-11-30 13:53

The Situation:

Working from a new project: iOS > Application > Game > SpriteKit, Swift, iPhone

Here I\'ve written a function in my G

2条回答
  •  悲&欢浪女
    2020-11-30 14:14

    See from the source code you should use CGFloat instead of Float

    enter image description here

    this should work

    func colorize (hex: Int, alpha: Double = 1.0) -> UIColor {
        let red = Double((hex & 0xFF0000) >> 16) / 255.0
        let green = Double((hex & 0xFF00) >> 8) / 255.0
        let blue = Double((hex & 0xFF)) / 255.0
        var color: UIColor = UIColor( red: CGFloat(red), green: CGFloat(green), blue: CGFloat(blue), alpha:CGFloat(alpha) )
        return color
    }
    

提交回复
热议问题