NightNight
  • September 18, 2023

NightNight makes it easy to integrate night mode. It provides multiple APIs which all contain keyword mixed.

If you want to implement night mode in Objective-C project without import swift code. This is the Objective-C version DKNightVersion

let view = UIView()
view.mixedBackgroundColor = MixedColor(normal: 0xffffff, night: 0x000000)

let imageView = UIImageView()
imageView.mixedImage = MixedImage(normal: UIImage(named: “normal”), night: UIImage(named: “night”))

Features


  •  Integrate night mode easily
  •  UIColor and UIImage support
  •  Support NSAttributedString
  •  Better autocompletion
  •  Customize with notification

Usage


  • Use MixedColor instead of UIColor

let view = UIView()

view.mixedBackgroundColor = MixedColor(normal: 0xffffff, night: 0x000000)

Use MixedImage instead of UIImage

let imageView = UIImageView()

imageView.mixedImage = MixedImage(normal: normal, night: night)

Support NSAttributedString

let attributedString = NSMutableAttributedString(string: “NightNight”)
attributedString.setMixedAttributes(
[NNForegroundColorAttributeName: MixedColor(normal: 0x000000, night: 0xfafafa)],
range: NSRange(location: 0, length: 9)
)

public let NNForegroundColorAttributeName
public let NNBackgroundColorAttributeName
public let NNUnderlineColorAttributeName

NavigationBar barStyle

let navigationBar = navigationController?.navigationBar

navigationBar.mixedBarStyle = MixedBarStyle(normal: .Default, night: .Black)

Change current theme to .NORMAL or .NIGHT

NightNight.theme = .NORMAL
NightNight.theme = .NIGHT

Customize


NightNight will send NightNightThemeChangeNotification. if you wanna some customize features, you can observe it and change what you want in corresponding selector.

public let NightNightThemeChangeNotification

Demo


Installation


Carthage

 Carthage is a decentralized dependency manager that automates the process of adding frameworks to your Cocoa application.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate NightNight into your Xcode project using Carthage, specify it in your Cartfile:

github “draveness/NightNight”

Cocoapods

CocoaPods is a dependency manager for Cocoa projects.

You can install it with the following command:

$ gem install cocoapods

To integrate NightNight into your Xcode project using CocoaPods, specify it in your Podfile:

use_frameworks!

pod ‘NightNight’

Manually

  1. Download and drop NightNight/Classesfolder in your project.
  2. Congratulations!

GitHub


View Github

#carthage #cocoapods #color #nightmode #swift #theme
YOU MIGHT ALSO LIKE...
exyte

     

camerakit-ios

CameraKit helps you add reliable camera to your app quickly. Our open source camera platform provides consistent capture results, service ...

HybridCamera

[video width="192" height="416" mp4="https://swiftgit.com/wp-content/uploads/2024/12/68747470733a2f2f7261776769742e636f6d2f7374796c656b69742f696d672f6d61737465722f7669645f6564697465645f325f326d622e676966.mp4"][/video]

TakeASelfie

An iOS framework that uses the front camera, detects your face and takes a selfie. This api opens the front ...

iOS-Depth-Sampler

Code examples of Depth APIs in iOS