Skip to content

Instantly share code, notes, and snippets.

@mntone
Created September 1, 2019 19:40
Embed
What would you like to do?
import struct PostoneCore.Settings
#if os(macOS)
import AppKit
public typealias POColor = NSColor
#else
import UIKit
public typealias POColor = UIColor
#endif
public extension POColor {
static let labelLight: POColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
static let labelDark: POColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
static let secondaryLabelLight: POColor = #colorLiteral(red: 0.2352941176, green: 0.2352941176, blue: 0.262745098, alpha: 0.6)
static let secondaryLabelDark: POColor = #colorLiteral(red: 0.9215686275, green: 0.9215686275, blue: 0.9607843137, alpha: 0.6)
static let systemBackgroundLight: POColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
static let systemBackgroundDark: POColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
}
public struct POColorCompatible {
private static func color(_ defaultColor: POColor, light lightColor: POColor, dark darkColor: POColor) -> POColor {
switch Settings.Theme.themeMode {
case .light:
return lightColor
case .dark:
return darkColor
default:
return defaultColor
}
}
public static var label: POColor {
if #available(iOS 13, *) {
return color(.label,
light: .labelLight,
dark: .labelDark)
} else {
return color(.labelLight,
light: .labelLight,
dark: .labelDark)
}
}
public static var secondaryLabel: POColor {
if #available(iOS 13, *) {
return color(.secondaryLabel,
light: .secondaryLabelLight,
dark: .secondaryLabelDark)
} else {
return color(.secondaryLabelLight,
light: .secondaryLabelLight,
dark: .secondaryLabelDark)
}
}
public static var systemBackground: POColor {
if #available(iOS 13, *) {
return color(.systemBackground,
light: .systemBackgroundLight,
dark: .systemBackgroundDark)
} else {
return color(.systemBackgroundLight,
light: .systemBackgroundLight,
dark: .systemBackgroundDark)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment