Set custom colors with RBG color

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.