Skip to content
No description, website, or topics provided.
Swift Objective-C
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.swiftpm/xcode/package.xcworkspace
DarkMode.xcworkspace
DarkMode
DarkModeExample
.gitignore
LICENSE
Package.swift
README.md

README.md

Dark Mode

Swift Version Carthage Compatible Swift Package Manager

DarkMode is a small framework that simplify configuration of light and dark user interface styles and reduce checks of available SDKs.

Requirements

  • iOS 12.0+ / tvOS 12.0+
  • Xcode 10.0+

Usage

DarkMode contains 6 extensions of UIKit components.

  1. UIColor extension contains an initializer with light and dark colors:

    static let layer = UIColor(light: .init(red: 106 / 255, green: 32 / 255, blue: 119 / 255, alpha: 1),
                               dark: .init(red: 138 / 255, green: 76 / 255, blue: 146 / 255, alpha: 1))
  2. UIImageAsset extension contains an initializer with light and dark images:

    let imageAsset = UIImageAsset(lightModeImage: UIImage(named: "RedRectangle"),
                                  darkModeImage: UIImage(named: "GreenRectangle"))
  3. UITraitCollection extension has optional check of different color appearance:

    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
        super.traitCollectionDidChange(previousTraitCollection)
        traitCollection.performForDifferentColorAppearance(comparedTo: previousTraitCollection) {
            //update related colors
        }
    }
  4. UIWindow extension allows you to override user interface style without SDK checks:

    UIApplication.shared.keyWindow?.override(.dark)
  5. UIApplication extension allows you to override user interface style for all windows without SDK checks:

    UIApplication.shared.override(.dark)
  6. UserDefaults extension allows you to save overrides user interface style:

    UserDefaults.standard.overridedUserInterfaceStyle = .dark

To see how it works together, please check DarkModeExample project.

Installation

Carthage

Create a Cartfile that lists the framework and run carthage update. Follow the instructions to add the framework to your project.

github "rosberry/DarkMode"

Manually

Drag DarkMode Swift files from last release into your project.

About

This project is owned and maintained by Rosberry. We build mobile apps for users worldwide 🌏.

Check out our open source projects, read our blog or give us a high-five on 🐦 @rosberryapps.

License

DarkMode is available under the MIT license. See the LICENSE file for more info.

You can’t perform that action at this time.