Skip to content

Library based on PerseusDarkMode with modern features like system and semantic colours for early iOS 9.3+, macOS 10.10+; Xcode 10.1+.

License

Notifications You must be signed in to change notification settings

perseusrealdeal/PerseusUISystemKit

Repository files navigation

Perseus UI System Kit

Actions Status Version Pod Platforms Swift 4.2 License

Integration Capabilities

Standalone Carthage compatible CocoaPods manager Swift Package Manager compatible

Dependencies

PerseusDarkMode

Demo Apps and Others

Demo App Demo App XcodeTemplateProject

In Brief

This library brings a developer some modern but simple tools like system and semantic colors, and dynamic image. Features of this library can be used to create Dark Mode sensitive UI for both macOS and iOS apps as well.

Reqirements

  • Xcode 10.1+
  • Swift 4.2+
  • iOS: 9.3+, UIKit SDK
  • macOS: 10.10+, AppKit SDK

First-party software

Third-party software

Installation

Using "Exact" with the Version field is strongly recommended.

Standalone

Make a copy of the file PerseusUISystemKitSingle.swift then put it into a place required of a host project.

Carthage

Cartfile should contain:

github "perseusrealdeal/PerseusDarkMode" == 1.1.5
github "perseusrealdeal/PerseusUISystemKit" == 1.1.4

Some Carthage usage tips placed here.

CocoaPods

Podfile should contain:

target "ProjectTarget" do
  use_frameworks!
  pod 'PerseusUISystemKit', '1.1.3'
end

Swift Package Manager

  • As a package dependency Package.swift should contain the following statements:
dependencies: [
        .package(url: "https://github.com/perseusrealdeal/PerseusUISystemKit.git",
            .exact("1.1.4"))
    ],
  • As an Xcode project dependency:

Project in the Navigator > Package Dependencies > Add Package Dependency

Using "Exact" with the Version field is strongly recommended.

Usage

Setup

Step 1: import PerseusDarkMode and call makeUp() in app's delegate:

import PerseusDarkMode

extension AppDelegate: UIApplicationDelegate {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions
        launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        // ... code

        // Call AppearanceService.makeUp() method if AppearanceService.register(:, :)
        // is taken into account
        AppearanceService.makeUp()

        // ... otherwise call AppearanceService.recalculateStyleIfNeeded()
        // to load DarkMode.style from user defaults
        // AppearanceService.recalculateStyleIfNeeded()
    }
}

Step 2: only if iOS, override method traitCollectionDidChange of the first app's screen, once

import PerseusDarkMode

class MainViewController: UIViewController {
    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
        super.traitCollectionDidChange(previousTraitCollection)

        if #available(iOS 13.0, *) {
            AppearanceService.processTraitCollectionDidChange(previousTraitCollection)
        }
    }
}

Using

Step 3: register a view controller of a screen

import PerseusDarkMode

class MainViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()

        AppearanceService.register(stakeholder: self, selector: #selector(makeUp))
    }

    @objc private func makeUp() {
        // UI customs put here
    }
}

Step 4: import PerseusUISystemKit and put all UI customs into makeUp() method

import PerseusDarkMode
import PerseusUISystemKit

class MainViewController: UIViewController {

    // ... code

    @objc private func makeUp() {
        print("^_^ \(DarkMode.style) \(UIColor.perseusBlue.RGBA255)")
        
        view.backgroundColor = .perseusBlue
    }
}

There is another way to be notified of Dark Mode—KVO.

DarkModeImageView class is an expressive sample of Dark Mode KVO usage for both macOS and iOS as well.

License MIT

Copyright © 7530 - 7531 Mikhail Zhigulin of Novosibirsk.

  • The year starts from the creation of the world according to a Slavic calendar.
  • September, the 1st of Slavic year.

LICENSE for details.

Author

PerseusUISystemKit was written at Novosibirsk by Mikhail Zhigulin i.e. me, mzhigulin@gmail.com.

Mostly I'd like thank my lovely parents for supporting me in all my ways.