UIColor

An object that stores color data and sometimes opacity.

There are several ways to select colors. The two important color identification systems are** RGB **and HSB. The most useful to programmers is the RGB or Red-Green-Blue color system. Each of the color components can be expressed separately as a value between 0 and 255, with 255 being the full color and 0 being no color.

Built-In UIColor Presets

There are a few built-in colors, which are accessed with class variables. These are the available preset colors:

Image for post

If you need to store these, like for background color, you would use the code:

let backgroundColor = UIColor.blue

Since this is a class variable, you call these presets directly from the UIColor class, without having to make an instance of it.

Creating a custom UIColor Object

Now, the presets above are useful, but if you want to make your own color i.e. somewhere between those colors. This can be done in swift by instantiating a custom UIColor object with an initializer.

These are some available initializers,

  • init(white: CGFloat, alpha: CGFloat)
  • init(hue: CGFloat, saturation: CGFloat, brightness: CGFloat, alpha: CGFloat)

#ios #swift #rgb #uicolor

UIColor in Swift-Make your apps colorful
1.45 GEEK