Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

jon kelson
5,149 Pointswhat is alpha colour
Hi What is alpha color when talking about enums etc ?
2 Answers

Greg Kaleka
39,021 PointsHi Jon,
Alpha is opacity, or lack of transparency. So when you specify an RGBA colour, you're describing first the RGB mix, and then how solid or see-through you want it to be. Alpha goes from 0 to 1, where 0 is completely see-through and invisible, and 1 is completely solid. The effect on the color itself will depend on what's behind the view you're changing.
In your code example, the function is returning a UIColor. The RGB and HSB values don't actually have numbers associated with them - they just need to be converted to numbers between 0 and 1 to work with UIColor. Alpha is already between 0 and 1 so it doesn't need to be divided by anything.

agreatdaytocode
24,757 PointsHi Jon, can you provide an example of the enum?
Note: The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque). Did you seen this in a course here or quiz?

jon kelson
5,149 PointsHi Aaron, thanks . here is the code , its from the coarse on enums in swift. it has no value so i was a bit confused wether it was a colour or not . such as this (alpha: alphaValue.) all the rest have colours and values.
num ColorComponents {
case RGB(CGFloat, CGFloat, CGFloat, CGFloat)
case HSB(CGFloat, CGFloat, CGFloat, CGFloat)
func color() -> UIColor {
switch self{
case .RGB(let redValue, let greenValue, let blueValue, let alphaValue)
return UIColor(red: redValue/255.0, green: greenValue/255.0, blue: blueValue/255.0, alpha: alphaValue)
case .HSB(let hughValue, let saturationValue, let brightnessValue, let alphaValue)
return UIColor(hue: hughValue/360.0, saturation: saturationValue/100.0, brightness: brightnessValue/100.0, alpha: alphaValue)
}
}
}