
This video is only available to subscribers. Start a subscription today to get access to this and 419 other videos.
Colors
Episode
#283
|
9 minutes
| published on
July 7, 2017
| Uses swift-3.0, Xcode-8.3
Subscribers Only
What are color spaces? Sam discusses the common color spaces you might use and what they are used for. Why would you use these methods instead of just using UIColor? If you want cross-platform compatible drawing code, you’ll want to know how this works.
This episode is part of a series: Dive Into Core Graphics.
1. Intro 2 min |
2. Basic Shapes 7 min |
3. Paths 17 min |
4. Colors 9 min |
5. Gradients 11 min |
6. Clipping Paths 6 min |
7. Context Transforms 10 min |
8. Images 7 min |
9. Text 9 min |
10. Offscreen Rendering 12 min |
11. Custom CALayer 13 min |
12. Pie Progress View 7 min |
13. Watermarking Photos 6 min |
14. Working in AppKit 8 min |
Getting a Color Space
// RGB
CGColorSpaceCreateDeviceRGB()
// Grayscale
CGColorSpaceCreateDeviceGray()
// CMYK
CGColorSpaceCreateDeviceCMYK()
Creating Colors with Color Spaces
let colorSpace = CGColorSpaceCreateDeviceRGB()
let color = CGColor(colorSpace: colorSpace, components: [0, 1, 0, 1])!
context.setFillColor(color)
context.fill(bounds)
context.setFillColor(CGColor(colorSpace: colorSpace, components: [0, 0, 1, 0.5])!)
context.setBlendMode(.normal)
context.fill(rect.insetBy(dx: 64, dy: 64))