This is the Mac's own color measurement meter.
Shortcut key SHIFT + COMMAND + C to copy the color of the RBG format
#DD0000 This is red in CSDN's logo.
We got a 16-bit color code.
But Uicolor () only has these kinds of initialization methods
CGFloat, alpha: CGFloat) init(hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat) init(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat)//这个是我们需要的 init(CGColor cgColor: CGColor!) init(patternImage image: UIImage) @availability(iOS, introduced=5.0) init(CIColor ciColor: CIColor)
Only cgfloat format is supported so we need to convert http://www.zzsky.cn/tool/rgb%5F16bit/into the website and then convert it to RGB color.
Get 221,0,0 RGB format color because the RGB binary is 226 binary, we need floating-point data, so when the value is divided by 225 here is a label for example
var Textlabel = UILabel (Frame:cgrectmake (10,30,uiscreen. Mainscreen (). Bounds. Size. Width-20,)) Textlabel. Text = "set Uilabel color" Textlabel.backgroundcolor = Self.view.backgroundcolor Textlabel .textcolor = Uicolor (red: 221/ 225, Green: 0/225, Blue: 0/225, Alpha: 1)//writes the resulting data here Textlabel.font = Uifont.systemfontofsize ( 22) textlabel.textalignment = NSTextAlignment.view.addsubview (text)
Set a custom color with RBG color