UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

UIColor

Found 6 articles in the Swift Knowledge Base for this category.

 

How to convert a hex color to a UIColor

Here's a simple extension to UIColor that lets you create colors from hex strings. The new method is a failable initializer, which means it returns nil if you don't specify a color in the correct format. It should be a # symbol, followed by red, green, blue and alpha in hex format, for a total of nine characters. For example, #ffe700ff is gold.... Continue Reading >>

How to convert a HTML name string into a UIColor

HTML color names let you use familiar titles like "steel blue" and "mint cream" rather than hex values, but sadly these standardized names aren't available in iOS – or at least not by default. Fortunately, it's easy to add an extension to UIColor that maps these names to hexadecimal color values, then add another extension to convert hex colors to UIColors. Here's the code:... Continue Reading >>

How to create custom colors using UIColor RGB and hues

Although there are quite a few built-in UIColors, you'll want to create your own very frequently. This can be done in a number of ways, but the most common is specifying individual values for red, green, blue and alpha, like this:... Continue Reading >>

How to read the red, green, blue, and alpha color components from a UIColor

Creating a UIColor from red, green, blue, and alpha (RGBA) is easy enough:... Continue Reading >>

How to use an image for your background color with UIColor(patternImage:)

Nearly all subclasses of UIView can have their background color adjusted, but often you’ll find you want to use an image rather than a flat color.... Continue Reading >>

How to use semantic colors to help your iOS app adapt to dark mode

When specifying colors for objects in your views, it’s often easier to use the built-in semantic colors of UIColor rather than specifying our own custom colors that might not look good in both light and dark mode.... Continue Reading >>

About the Swift Knowledge Base

This is part of the Swift Knowledge Base, a free, searchable collection of solutions for common iOS questions, all written for Swift 5.4.

BUY OUR BOOKS
Buy Pro Swift Buy Pro SwiftUI Buy Swift Design Patterns Buy Testing Swift Buy Hacking with iOS Buy Swift Coding Challenges Buy Swift on Sundays Volume One Buy Server-Side Swift Buy Advanced iOS Volume One Buy Advanced iOS Volume Two Buy Advanced iOS Volume Three Buy Hacking with watchOS Buy Hacking with tvOS Buy Hacking with macOS Buy Dive Into SpriteKit Buy Swift in Sixty Seconds Buy Objective-C for Swift Developers Buy Beyond Code

Was this page useful? Let us know!

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.