Simple UIColor references in Swift

I find it really frustrating that there’s no built-in Hex colours in Swift. It means I have to convert my usual simple values into RGB. What makes this more annoying is that the UIColor function accepts Float values between 0 and 1, meaning you then have to convert those to some ridiculous floating number.

However, if you just use it as below then you don’t have to do that second part. Just makes life a little bit more pleasant and the colours that little bit more accurate.

UIColor(red: x/255.0, green: y/255.0, blue: z/255.0, alpha: 1.0)

Obviously you can set alpha to whatever you prefer as well.

Hope that’s useful to someone, I just used it in a current dev app and thought it might be handy as I hadn’t considered it before.