SwiftPiecesComponents

Styles

SwiftPieces · your style

Character

Regular · Regular
AiryCompactQuietBold

Color

#FF0000

Typography

Shape

Feel

Open in the Playground
TimepagePocket CastsWaterllamaHevyMercury Weather

Swift for this style

Apps you build from the Playground already include Theme.swift. For an app of your own, add Theme.swift to the project and give your App the root below: every view under it follows the style.

import SwiftUI
import UIKit

/// The app's look, made in SwiftPieces Styles (SwiftPieces). Change a value here
/// and every screen follows. The accent is also the app's AccentColor asset.
enum Theme {
    /// Buttons, links, selection and tinted controls.
    static let accent = Color(light: 0xFF0000, dark: 0xFF0000)
    /// Text and icons that sit on the accent.
    static let accentInk = Color(light: 0x121212, dark: 0x121212)
    /// Screen backgrounds.
    static let background = Color(light: 0xF3F2EE, dark: 0x070708)
    /// Cards and grouped content.
    static let surface = Color(light: 0xFFFFFF, dark: 0x141416)
}

extension Theme {
    /// How things move: the app's spring.
    static let motion: Animation = .smooth
}

extension View {
    /// A card in the app's style (flat).
    func themeCard(cornerRadius: CGFloat) -> some View {
        modifier(ThemeCard(radius: cornerRadius))
    }
}

struct ThemeCard: ViewModifier {
    let radius: CGFloat

    func body(content: Content) -> some View {
        let shape = RoundedRectangle(cornerRadius: radius, style: .continuous)
        return content.background(.fill.tertiary, in: shape)
    }
}

extension Color {
    /// A color that switches with light and dark mode.
    init(light: UInt32, dark: UInt32) {
        self.init(uiColor: UIColor { traits in
            let value = traits.userInterfaceStyle == .dark ? dark : light
            return UIColor(
                red: CGFloat((value >> 16) & 0xFF) / 255,
                green: CGFloat((value >> 8) & 0xFF) / 255,
                blue: CGFloat(value & 0xFF) / 255,
                alpha: 1
            )
        })
    }
}