I am working on building a color wheel picker UI for an iOS app. While there are several great Color Wheels that the developer community has written, I am actually trying to build a Color Wheel from scratch to understand how these color wheels and UIs are made. One of the first things is figuring out how to convert HSB values to RGB. I made a quick Swift Playground to get started:
// ColorExperiments Playground
import UIKit
// A HSB color where:
// H = 5 degrees out of 360 degrees
// S = 91% -> 0.91
// B = 100% -> 1.0
var hueColor = UIColor.init(hue: 5/360, saturation: 0.91, brightness: 1.0, alpha: 1.0)
// The RGB equivalent should be
// R = 255
// G = 42
// B = 23
I tried looking into the UIKit documentation and online, maybe I missed it, but is there an API in UIColor that allows me to convert the HSB to RGB color? I found some third party functions. I'm guessing UIColor should have something since the Swift Playgrounds sidebar shows me the my hueColor variable as the RGB equivalent unless that's some private function that Apple is using.
Thanks!