问题描述
The Color
initializer init(hue:saturation:brightness:opacity:)
is undocumented。
我认为我可以放心地假设saturation
,brightness
和opacity
归一化为0...1
的范围,其中超出该范围的值仅对宽范围有效,色域显示。
但是我无法为hue
做这个猜测。是0...1
,0...τ
还是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()
}
}