Last active
July 24, 2020 15:40
-
-
Save Clarko/df17edb84b79334c85895454f109f072 to your computer and use it in GitHub Desktop.
SwiftUI Color Extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ConvenientColors.swift | |
// | |
// Created by Clarko on 7/15/20. | |
// | |
// Color.primary and Color.secondary are great for foreground text | |
// that adapts in light & dark mode, but there are a lot more | |
// UI Element Colors in iOS and macOS: | |
// | |
// https://developer.apple.com/documentation/uikit/uicolor/ui_element_colors | |
// | |
// https://developer.apple.com/documentation/appkit/nscolor/ui_element_colors | |
// | |
// Here are my shortcuts to a handful of common colors, | |
// with idiomatic names. | |
import SwiftUI | |
extension Color { | |
#if os(iOS) | |
// Foreground | |
static var tertiary: Color { | |
Color(.tertiaryLabel) | |
} | |
// Backgrounds | |
static var primaryBackground: Color { | |
Color(.systemBackground) | |
} | |
static var secondaryBackground: Color { | |
Color(.secondarySystemBackground) | |
} | |
static var tertiaryBackground: Color { | |
Color(.tertiarySystemBackground) | |
} | |
// GroupedListStyle and Form Backgrounds | |
static var primaryGroupedBackground: Color { | |
Color(.systemGroupedBackground) | |
} | |
static var secondaryGroupedBackground: Color { | |
Color(.secondarySystemGroupedBackground) | |
} | |
static var tertiaryGroupedBackground: Color { | |
Color(.tertiarySystemGroupedBackground) | |
} | |
#elseif os(macOS) | |
// Foreground | |
static var tertiary: Color { | |
Color(.tertiaryLabelColor) | |
} | |
// Backgrounds | |
static var primaryBackground: Color { | |
Color(.textBackgroundColor) | |
} | |
#endif | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment