1

I found this code part on GitHub and it works really fine, I can even change the color by clicking on the color cube. Also, I could copy the color cube and use anywhere I wanted. I want to know how to initialize this in Swift 3.

color cubes in code

I tried this but couldn't figure it out.

    let cc = [UIColor(red: CGFloat(160/255), green: CGFloat(183.0/255), blue: CGFloat(227.0/255), alpha: 1), UIColor(red: CGFloat(160/255), green: CGFloat(183.0/255), blue: CGFloat(227.0/255), alpha: 1)]
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
ajw
  • 2,568
  • 23
  • 27

2 Answers2

1

You should use color literals in order to achieve this.

#colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)

In fact, you shouldn't even memorize this, as the autocompletion will show a Color Literal option to you if you start typing it in.

Color Literal autocompletion

After that, double-click on the appearing square and you can pick from colors there:

color picker popover

Clicking on Other... reveals the standard color picker of macOS:

the standard color picker of macOS

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
0

If you are creating color literals in one of your model files, do not forget import UIKit before you do this.