Elegant way to integrate night mode to swift projects

Overview

Travis Status CocoaPods compatible Carthage compatible Platform

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")) 

FeaturesUsageCustomizeDemoInstallationLicense

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!

License

Copyright (c) 2016 Draveness (http://github.com/draveness)

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

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Comments
  • Segmentation fault: 11 when archiving app for release

    Segmentation fault: 11 when archiving app for release

    The offending file is UIButton+Mixed.swift

    0  swift                    0x000000010d3ffb6d PrintStackTraceSignalHandler(void*) + 45
    1  swift                    0x000000010d3ff5b6 SignalHandler(int) + 470
    2  libsystem_platform.dylib 0x00007fff9fc5852a _sigtramp + 26
    3  libsystem_platform.dylib 000000000000000000 _sigtramp + 1614445296
    4  swift                    0x000000010a99f472 (anonymous namespace)::GlobalNumberState::getNumber(llvm::GlobalValue*) + 82
    5  swift                    0x000000010a99e3be (anonymous namespace)::FunctionComparator::cmpConstants(llvm::Constant const*, llvm::Constant const*) const + 622
    6  swift                    0x000000010a99c497 (anonymous namespace)::SwiftMergeFunctions::FunctionNodeCmp::operator()((anonymous namespace)::SwiftMergeFunctions::EquivalenceClass const&, (anonymous namespace)::SwiftMergeFunctions::EquivalenceClass const&) const + 5447
    7  swift                    0x000000010a997026 (anonymous namespace)::SwiftMergeFunctions::runOnModule(llvm::Module&) + 3158
    8  swift                    0x000000010d24aada llvm::legacy::PassManager::run(llvm::Module&) + 890
    9  swift                    0x000000010a94a3f1 performLLVM(swift::IRGenOptions&, swift::DiagnosticEngine&, llvm::sys::SmartMutex<false>*, llvm::GlobalVariable*, llvm::Module*, llvm::TargetMachine*, llvm::StringRef) + 6145
    10 swift                    0x000000010a9484b2 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 2514
    11 swift                    0x000000010a8161c7 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 23687
    12 swift                    0x000000010a80e265 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17029
    13 swift                    0x000000010a7cb82d main + 8685
    14 libdyld.dylib            0x00007fff8e3745ad start + 1
    15 libdyld.dylib            0x0000000000000068 start + 1908980412
    

    It runs great on device (but I am currently not using the UIButton extension), I just cannot archive the project.

    opened by tthbalazs 3
  • night and normal background color not working.

    night and normal background color not working.

    I am setting night background and normal background color in storyboard but its not working. I tried to print property mixedBackgroundColor of view but it shows nil.

    opened by commando24 2
  • How to switch the color of buttonBarBackgroundColor using XLPagerTabStrip

    How to switch the color of buttonBarBackgroundColor using XLPagerTabStrip

    self.settings.style.buttonBarBackgroundColor don't have mixedBackgroundColor , so i use it

            if NightNight.theme == .normal {
                self.settings.style.buttonBarBackgroundColor = UIColor(CNodeColor.backgroundColor)
                self.settings.style.buttonBarItemBackgroundColor = UIColor(CNodeColor.backgroundColor)
            } else {
                self.settings.style.buttonBarBackgroundColor = UIColor(CNodeColor.backgroundColor_dark)
                self.settings.style.buttonBarItemBackgroundColor = UIColor(CNodeColor.backgroundColor_dark)
            }
    

    when i execute NightNight.theme = .night It has not changed.

    In addition

    how to use NightNightThemeChangeNotification ? Can you give a demo ?

    opened by atjiu 1
  • Archiving issue

    Archiving issue

    Hello!

    Wonderful library, thank you!

    As mentioned in the other issue, I cannot archive my application as long as I have NightNight included in my workspace. When removing it from my Podfile (and pod install) and removing all the code I use from NightNight, Xcode archives fine.

    However when I add

    pod 'NightNight', :git => 'https://github.com/Draveness/NightNight.git', :branch => 'swift3.0'

    the app builds fine! But the archiving does not work, as mentioned.

    When I instead use

    pod 'NightNight'

    I cannot even build the application because the branch (master) seems to be not Swift 3 compatible. I'm working with Xcode 8.

    Please kindly help!

    Thanks!

    opened by ArturGasparyan 1
  • Carthage error

    Carthage error

    Upon attempting to install NightNight via Carthage, I get this error:

    *** Cloning NightNight
    *** Checking out NightNight at "0.3.1"
    *** xcodebuild output can be found in /var/folders/m2/42zy198s57568lwz02wk_nfh0000gn/T/carthage-xcodebuild.JjviUH.log
    A shell task (/usr/bin/xcrun xcodebuild -project /Users/Mathew/Desktop/StudyPlus/Carthage/Checkouts/NightNight/Example/Pods/Pods.xcodeproj CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES -list) failed with exit code 74:
    xcodebuild: error: Unable to read project 'Pods.xcodeproj' from folder '/Users/Mathew/Desktop/StudyPlus/Carthage/Checkouts/NightNight/Example/Pods'.
    	Reason: Project /Users/Mathew/Desktop/Project/Carthage/Checkouts/NightNight/Example/Pods/Pods.xcodeproj cannot be opened because it is missing its project.pbxproj file.
    

    Additionally, downloading the xcode project and attempting to run it does not work either. It presents many errors.

    opened by ghost 1
  • Manual Installation

    Manual Installation

    CocoaPods and Carthage are awesome tools and make our life really easier, but there are some devs who still don't know how to use them.

    It would be cool to add the Manual installation guide in your README.md. You can take a look at my iOS Readme Template to see how you can do it.

    opened by lfarah 1
  • UITabBar is missing mixedBarStyle property

    UITabBar is missing mixedBarStyle property

    tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.black ,NSFontAttributeName:UIFont.systemFont(ofSize: 10)] , for: UIControlState())

    opened by menicor 0
  • i am getting compiler errors while building.

    i am getting compiler errors while building.

    screen shot 2017-01-24 at 1 58 34 pm

    When i tried to update the podfile, i am getting the following error: [!] Unable to satisfy the following requirements:

    • NightNight (~> 0.4.1) required by Podfile

    None of your spec sources contain a spec satisfying the dependency: NightNight (~> 0.4.1).

    You have either:

    • out-of-date source repos which you can update with pod repo update.
    • mistyped the name or version.
    • not added the source repo that hosts the Podspec to your Podfile.

    Note: as of CocoaPods 1.0, pod repo update does not happen on pod install by default.

    opened by ashiqsulaiman 0
  • Mixed keyboard appearance swift3

    Mixed keyboard appearance swift3

    I have added support for mixedKeyboardAppearance to UITextField and UISearchBar. Use for example searchBar.mixedKeyboardAppearance = MixedKeyboardAppearance(normal: .light, night: .dark)

    opened by noisyscanner 0
  • UINavigationBar is not in night mode when presented like this

    UINavigationBar is not in night mode when presented like this

    the resulting navigation controller has a .normal mode colour even when night mode is enabled

    func addPressed() {
            let newItemView = AddItemViewController()
            let nav = UINavigationController(rootViewController: newItemView)
            present(nav, animated: true, completion: nil)
    }
    
    opened by halpz 4
  • Fixed the color won't change when use the Storyboard to set the background color of UIView

    Fixed the color won't change when use the Storyboard to set the background color of UIView

    Hello. Thanks for your work. I found that the color won't change when I use the Storyboard to set the background color of UIView. So I modify the code in "UIView+IBInspectable.swift" and "UIView+Mixed.swift".

    opened by zyphs21 1
  • IBInspectable values are not reflecting

    IBInspectable values are not reflecting

    When you set background colour values from Storyboard then it is not reflecting at run time. In short I have to go programatically to change background colour.

    opened by ganeshkhedkaraa 1
Owner
Draven
Go / Rails / Rust
Draven
Elegant Apply Style by Swift Method Chain.🌙

ApplyStyleKit ApplyStyleKit is a library that applies styles to UIKit using Swifty Method Chain. Normally, when applying styles to UIView etc.,it is n

shindyu 203 Nov 22, 2022
Create macOS apps with Swift packages instead of Xcode projects

Swift Bundler A Swift Package Manager wrapper that allows the creation of MacOS apps with Swift packages instead of Xcode projects. My motivation is t

null 182 Dec 25, 2022
🚀 Elegant Pager View fully written in pure SwiftUI.

PagerTabStripView Made with ❤️ by Xmartlabs team. XLPagerTabStrip for SwiftUI! Introduction PagerTabStripView is the first pager view built in pure Sw

xmartlabs 482 Jan 9, 2023
UIAdapter - An elegant solution to the iOS screen adaptation problem

UIAdapter - An elegant solution to the iOS screen adaptation problem ???? 天朝子民 Features Numerical type fast conversion Storyboard equal scale adaptati

LEE 39 Dec 25, 2022
Creating a simple selectable tag view in SwiftUI is quite a challenge. here is a simple & elegant example of it.

SwiftUI TagView Creating a simple selectable tag view in SwiftUI is quite a challenge. here is a simple & elegant example of it. Usage: Just copy the

Ahmadreza 16 Dec 28, 2022
FSPagerView is an elegant Screen Slide Library implemented primarily with UICollectionView.

FSPagerView is an elegant Screen Slide Library implemented primarily with UICollectionView. It is extremely helpful for making Banner、Product Show、Welcome/Guide Pages、Screen/ViewController Sliders.

Wenchao Ding 6.7k Jan 2, 2023
ElongationPreview is an elegant UI push-pop style view controller

ElongationPreview is an elegant UI push-pop style view controller

Ramotion 886 Dec 19, 2022
A simple and elegant UIKit for iOS.

HamsterUIKit A simple and elegant UIKit(Chart) for iOS, written in Swift. ?? Curve and bar Charts. ?? Protocols are designed based on UIKit(UITableVie

Howard Wang 30 Oct 2, 2022
Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.

Twinkle ✨ Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle. This library creates several CAEmitterLayers and animate

patrick piemonte 600 Nov 24, 2022
A way to quickly add a notification badge icon to any view. Make any view of a full-fledged animated notification center.

BadgeHub A way to quickly add a notification badge icon to any view. Demo/Example For demo: $ pod try BadgeHub To run the example project, clone the r

Jogendra 772 Dec 28, 2022
A better way to present a SFSafariViewController or start a ASWebAuthenticationSession in SwiftUI.

BetterSafariView A better way to present a SFSafariViewController or start a ASWebAuthenticationSession in SwiftUI. Contents Motivation Requirements U

Dongkyu Kim 392 Dec 31, 2022
Fashion is your helper to share and reuse UI styles in a Swifty way.

Fashion is your helper to share and reuse UI styles in a Swifty way. The main goal is not to style your native apps in CSS, but use a set

Vadym Markov 124 Nov 20, 2022
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.

LoadingShimmer An easy way to add a shimmering effect to any view with just single line of code. It is useful as an unobtrusive loading indicator. Thi

Jogendra 1.4k Jan 4, 2023
Custom emojis are a fun way to bring more life and customizability to your apps.

Custom emojis are a fun way to bring more life and customizability to your apps. They're available in some of the most popular apps, such as Slack, Di

Stream 244 Dec 11, 2022
List tree data souce to display hierachical data structures in lists-like way. It's UI agnostic, just like view-model and doesn't depend on UI framework

SwiftListTreeDataSource List tree data souce to display hierachical data structures in lists-like way. It's UI agnostic, just like view-model, so can

Dzmitry Antonenka 26 Nov 26, 2022
The Bloc Pattern is a way to separate UI and Logic in SwiftUI codes;

The Bloc Pattern is a way to separate UI and Logic in SwiftUI codes. The Bloc is like a state machine where it accepts an event and produce a state.

mehdi sohrabi 3 Apr 20, 2022
A simple way to hide the notch on the iPhone X

NotchKit NotchKit is a simple way to hide the notch on the iPhone X, and create a card-like interface for your apps. Inspired by this tweet from Sebas

Harshil Shah 1.8k Dec 5, 2022
DrawerKit lets an UIViewController modally present another UIViewController in a manner similar to the way Apple's Maps app works.

DrawerKit What is DrawerKit? DrawerKit is a custom view controller presentation mimicking the kind of behaviour in the Apple Maps app. It lets any vie

Babylon Health 773 Dec 27, 2022
ToastSwiftUI-master - A simple way to show a toast or a popup in SwiftUI

ToastSwiftUI-master - A simple way to show a toast or a popup in SwiftUI

Kushal Shingote 2 May 25, 2022