So There are answers to this on SO but they are old and as far as I can tell in objectiveC
, so...
I want to set the backgroundcolor
using Int
variables passed from a different view
, like this:
backgroundView.backgroundColor = UIColor(red: red/255, green: green/255, blue: blue/255, alpha: 0.5)
The variables red
green
blue
used are like this:
var red: Int!
var green: Int!
var blue: Int!
With numbers from the previous view
of course.
Xcode wants me to convert it to CGFloat
like this:
backgroundView.backgroundColor = UIColor(red: CGFloat(red/255), green: CGFloat(green/255), blue: CGFloat(blue/255), alpha: 0.5)
But then the right color isn't carried over and only grey is shown.
I tried changing the Int
variables to UIColor
var red: UIColor!
But that gave me an error...
So, how do I fix this?