Color.inithue:saturation:Brightness:opacity:`中的色相值范围是多少?

问题描述

The Color initializer init(hue:saturation:brightness:opacity:) is undocumented

我认为我可以放心地假设saturationbrightnessopacity归一化为0...1的范围,其中超出该范围的值仅对宽范围有效,色域显示

但是我无法为hue做这个猜测。是0...10...τ还是0...360

解决方法

很高兴,快速进行测试很容易。

我将此代码扔到了一个新的SwiftUI应用中,只是看着预览来查看结果。事实证明,0...1

import SwiftUI

struct ContentView: View {
    var body: some View {
        VStack(spacing: 0) {
            Color(hue: 0/6,saturation: 1,brightness: 1)
            Color(hue: 1/6,brightness: 1)
            Color(hue: 2/6,brightness: 1)
            Color(hue: 3/6,brightness: 1)
            Color(hue: 4/6,brightness: 1)
            Color(hue: 5/6,brightness: 1)
            Color(hue: 6/6,brightness: 1)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

A screenshot proving that the range is 0...1 by showing colors with hues 0/6 through 6/6 in a VStack