From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Using hex color

Using hex color

- [Instructor] There's a lot of ways to represent colors. Crayons have names like Sea Green and Peach. As developers, we usually use RGB colors. UIColor has an initializer for RGB, using CG float values between zero and one. One of the most common shorthands for RGB values used in web and graphic design applications is the six-digit hexadecimal value. UIKit does not include an initializer for this value. Fortunately, with some bit manipulation, you've learned in a previous step it's easy to convert from a hex value to a UIColor. Let me show you how, and a quick tip to get a matching color. Hex colors use eight bits, or two hex digits, to represent each of the three primary colors in an RGB color. The rightmost two digits are blue. Next to that, green, and to the left, red. If you separate those numbers ranging from zero to 255, you can divide them by 255 and get the values for UIColor. Let's try that. On github, you can find the starter file, which has an application for setting the…

Contents