Learn how to use a HEX color string like β#808080β(grey hex color code) in Swift with UIColor.
In this article, we will learn how to convert a HEX color value like β#808080β(grey hex color code) to UIColor in Swift.
Most designers and color pickers are working with hex color values, but there is no builtin conversion from a hex string to UIColor. Letβs dive in and create a UIColor Swift extension that you can use to paste hex values directly into your swift code.
We will create a failable initializer, which will return nil if you specify a color in the wrong format.
The hex string should start with β#β character and have red, green, blue and alpha components.
β
Now you can easily use this function to initialize UIColor with a hex color value.
We donβt just convert colors. Oh, no. We have the powerful color editing software you will ever need. If you need to pick a color from the screen, we can help you with that. If you need to generate a visually pleasing color palette, we can help you with that too. Itβs not a problem, with Pikka.
Download now