Created
July 18, 2023 13:07
-
-
Save Johnny1776/c19d4870284a9354444f9017fc16a21d to your computer and use it in GitHub Desktop.
Simple View represents common UI System Colors for iOS and macOS.
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
| import SwiftUI | |
| #if os(iOS) | |
| import UIKit | |
| #endif | |
| /** | |
| Display a simple view of the common system colors used for interface design. Quick reference that if in Canvas will display in a larger format. | |
| */ | |
| struct ExampleColorSchemes: View { | |
| var isPreviewWindow = false | |
| let columns = [GridItem(.adaptive(minimum: 140))] | |
| var body: some View { | |
| ScrollView { | |
| LazyVGrid(columns: columns, spacing: 12) { | |
| ForEach(ColorSection.allCases, id: \.self) { section in | |
| Section(header: Text(section.rawValue).font(.title2).bold().padding()) { | |
| ForEach(section.colors, id: \.self) { color in | |
| VStack(alignment: .center, spacing: 0) { | |
| Spacer() | |
| Text(color.debugDescription.replacingOccurrences(of: "Catalog color: System ", with: "")) | |
| .lineLimit(2) | |
| .multilineTextAlignment(.center) | |
| .fontWeight(.ultraLight) | |
| .minimumScaleFactor(0.8) | |
| .padding([.horizontal, .bottom],6) | |
| Rectangle() | |
| .fill(Color(color)) | |
| .frame(height: 50) | |
| .cornerRadius(10) | |
| } | |
| .frame(width: 140) | |
| .overlay(RoundedRectangle(cornerRadius: 10).stroke(Color.white, lineWidth: 0.4)) | |
| } | |
| } | |
| } | |
| } | |
| .padding() | |
| LazyVGrid(columns: columns) { | |
| ForEach(ColorNames.allCases, id: \.self) { color in | |
| VStack(alignment: .leading) { | |
| Text(color.rawValue) | |
| .frame(width: 80, alignment: .leading) | |
| Rectangle() | |
| .fill(color.color) | |
| .frame(width: 50, height: 50) | |
| .border(Color.black) | |
| } | |
| } | |
| } | |
| .frame(maxWidth: .infinity, maxHeight: .infinity) | |
| .padding() | |
| } | |
| .frame(width: isPreviewWindow ? 800 : nil, height:isPreviewWindow ? 2000 : nil) | |
| } | |
| } | |
| #if os(iOS) | |
| enum ColorSection: String, CaseIterable { | |
| case label = "Label Colors" | |
| case fill = "Fill Colors" | |
| case text = "Text Colors" | |
| case tint = "Tint Colors" | |
| case standardBackground = "Standard Background Colors" | |
| case groupedBackground = "Grouped Background Colors" | |
| case separator = "Separator Colors" | |
| case link = "Link Colors" | |
| case nonAdaptable = "Non-Adaptable Colors" | |
| var colors: [UIColor] { | |
| switch self { | |
| case .label: | |
| return [UIColor.label, UIColor.secondaryLabel, UIColor.tertiaryLabel, UIColor.quaternaryLabel] | |
| case .fill: | |
| return [UIColor.systemFill, UIColor.secondarySystemFill, UIColor.tertiarySystemFill, UIColor.quaternarySystemFill] | |
| case .text: | |
| return [UIColor.placeholderText] | |
| case .tint: | |
| return [UIColor.tintColor] | |
| case .standardBackground: | |
| return [UIColor.systemBackground, UIColor.secondarySystemBackground, UIColor.tertiarySystemBackground] | |
| case .groupedBackground: | |
| return [UIColor.systemGroupedBackground, UIColor.secondarySystemGroupedBackground, UIColor.tertiarySystemGroupedBackground] | |
| case .separator: | |
| return [UIColor.separator, UIColor.opaqueSeparator] | |
| case .link: | |
| return [UIColor.link] | |
| case .nonAdaptable: | |
| return [UIColor.darkText, UIColor.lightText] | |
| } | |
| } | |
| } | |
| #elseif os(macOS) | |
| enum ColorSection: String, CaseIterable { | |
| case label = "Label Colors" | |
| case text = "Text Colors" | |
| case content = "Content Colors" | |
| case menu = "Menu Colors" | |
| case table = "Table Colors" | |
| case control = "Control Colors" | |
| case window = "Window Colors" | |
| case highlightsAndShadows = "Highlights and Shadows" | |
| var colors: [NSColor] { | |
| switch self { | |
| case .label: | |
| return [NSColor.labelColor, NSColor.secondaryLabelColor, NSColor.tertiaryLabelColor, NSColor.quaternaryLabelColor] | |
| case .text: | |
| return [NSColor.textColor, NSColor.placeholderTextColor, NSColor.selectedTextColor, NSColor.textBackgroundColor, NSColor.selectedTextBackgroundColor, NSColor.keyboardFocusIndicatorColor, NSColor.unemphasizedSelectedTextColor, NSColor.unemphasizedSelectedTextBackgroundColor] | |
| case .content: | |
| return [NSColor.linkColor, NSColor.separatorColor, NSColor.selectedContentBackgroundColor, NSColor.unemphasizedSelectedContentBackgroundColor] | |
| case .menu: | |
| return [NSColor.selectedMenuItemTextColor] | |
| case .table: | |
| return [NSColor.gridColor, NSColor.headerTextColor] | |
| case .control: | |
| return [NSColor.controlAccentColor, NSColor.controlColor, NSColor.controlBackgroundColor, NSColor.controlTextColor, NSColor.disabledControlTextColor, NSColor.selectedControlColor, NSColor.selectedControlTextColor, NSColor.alternateSelectedControlTextColor, NSColor.scrubberTexturedBackground] | |
| case .window: | |
| return [NSColor.windowBackgroundColor, NSColor.windowFrameTextColor, NSColor.underPageBackgroundColor] | |
| case .highlightsAndShadows: | |
| return [NSColor.findHighlightColor, NSColor.highlightColor, NSColor.shadowColor] | |
| } | |
| } | |
| } | |
| #endif | |
| //SwiftUI Colors | |
| enum ColorNames: String, CaseIterable { | |
| case black | |
| case blue | |
| case brown | |
| case clear | |
| case cyan | |
| case gray | |
| case green | |
| case indigo | |
| case mint | |
| case orange | |
| case pink | |
| case purple | |
| case red | |
| case teal | |
| case white | |
| case yellow | |
| case accentColor | |
| case primary | |
| case secondary | |
| case tertiary | |
| var color: Color { | |
| switch self { | |
| case .black: return Color.black | |
| case .blue: return Color.blue | |
| case .brown: return Color.brown | |
| case .clear: return Color.clear | |
| case .cyan: return Color.cyan | |
| case .gray: return Color.gray | |
| case .green: return Color.green | |
| case .indigo: return Color.indigo | |
| case .mint: return Color.mint | |
| case .orange: return Color.orange | |
| case .pink: return Color.pink | |
| case .purple: return Color.purple | |
| case .red: return Color.red | |
| case .teal: return Color.teal | |
| case .white: return Color.white | |
| case .yellow: return Color.yellow | |
| case .accentColor: return Color.accentColor | |
| case .primary: return Color.primary | |
| case .secondary: return Color.secondary | |
| #if os(macOS) | |
| case .tertiary: return Color(NSColor.tertiaryLabelColor) | |
| #endif | |
| } | |
| } | |
| } | |
| struct ExampleColorSchemes_Previews: PreviewProvider { | |
| static var previews: some View { | |
| ExampleColorSchemes(isPreviewWindow: true) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment