Andrew Bancroft 6/26/2015

Swift UIColor Extension – Create using RGB Values (Not %)

Read Original

This article discusses a common pitfall in iOS development where developers mistakenly pass raw RGB values (0-255) to UIColor's initializer, which expects values between 0.0 and 1.0. The author shares a simple Swift extension that adds a static method to UIColor, allowing RGB values to be used directly by dividing them by 255.0 internally. This is a practical tip for iOS developers working with color palettes in code, helping avoid a frequent error and keeping color definitions centralized.

Swift UIColor Extension – Create using RGB Values (Not %)

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser