Has anyone experienced this problem? It looks like a bug in Apple's code and I will submit a radar if people agree that this code should do what I think it should do. I'm not all that familiar with CoreGraphics
color management, hence I'm asking before I bug Apple with a bug report.
This is straight out of a template project and the only non-template code is what you see below. Note that the red, green, and blue colors all show the correct component values but not white or black.
The problem persists if you change the order with, say, black and white first, then red, green, blue.
This is Swift 1.2 and Xcode 6.3.1 (6D1002).
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let colorComps = [
CGColorGetComponents(UIColor.redColor().CGColor),
CGColorGetComponents(UIColor.greenColor().CGColor),
CGColorGetComponents(UIColor.blueColor().CGColor),
CGColorGetComponents(UIColor.blackColor().CGColor),
CGColorGetComponents(UIColor.whiteColor().CGColor)
]
var components = [CGFloat]()
for cc in colorComps
{
for i in 0...3 { components.append(cc[i]) }
}
println("components: (components)")
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…