Initialize UIColor from RGB hex in Swift

Want to initialize a UIColor object from a hex code?

Create a new Swift class named “UIColor+FromRGB.swift” with the following content:

Initializing a UIColor object then is now a matter of a one-liner, e.g.:

 

Leave a Reply

Your email address will not be published. Required fields are marked *


Notice: Undefined index: rerror in /var/www/manuelbaumann.com/htdocs/wp-content/plugins/wp-recaptcha/recaptcha.php on line 291