Avatar ·

How to use hex color values in Swift (UIColor)?

Hello everyone! I'm new to iOS development and writing in Swift. I've encountered a problem: the design gave me colors in HEX format (e.g., `#FF5733`), but the standard `UIColor` class doesn't seem to work with hex strings directly. I tried doing this: ```swift let myColor = UIColor(hex: "#FF5733") // Error! ``` But Xcode throws an error — there's no such initializer. I've tried searching for ready-made solutions online, but I only find different pieces of code that don't always work. For example, some suggest manually splitting hex into RGB components, but that's very inconvenient when there are many colors. Others recommend writing extensions, but I'm not sure how to do it correctly to support both 6-character hex (without alpha channel) and 8-character hex (with transparency). Please advise how to pr