Giter VIP home page Giter VIP logo

nightnight's Introduction

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.

nightnight's People

Contributors

emreozdil avatar fredericdnd avatar glushchenko avatar lfarah avatar maxadamyan avatar melsam avatar noisyscanner avatar weiran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nightnight's Issues

UITabBar is missing mixedBarStyle property?

Not sure if I'm missing something but I think that UITabBars don't have a mixedBarStyle property. The only way I can get this to work is by adding the following code (taken from NightNight's UINavigationBar extension) to the Classes/UIKit/UITabBar+Mixed.swift file.

public extension UITabBar {
    fileprivate struct AssociatedKeys {
        static var mixedBarStyleKey = "mixedBarStyleKey"
    }
    
    public var mixedBarStyle: MixedBarStyle? {
        get {
            return objc_getAssociatedObject(self, &AssociatedKeys.mixedBarStyleKey) as? MixedBarStyle
        }
        set {
            objc_setAssociatedObject(self, &AssociatedKeys.mixedBarStyleKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
            
            addNightObserver(#selector(_updateBarStyle))
        }
    }
    
    func _updateBarStyle() {
        if let mixedBarStyle = mixedBarStyle {
            barStyle = mixedBarStyle.unfold()
        }
    }
    
}

Is there another way of giving a MixedBarStyle to a UITabBar or was it accidentally left out of the code?

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.

Swift 4.0 support

Just asking when do you think NightNight will be compatible with Swift 4?

Thank's for your amazing job.

NNForegroundColorAttributeName does not react to mode change

let attributedString = NSMutableAttributedString(string: "NightNight")
attributedString.setMixedAttributes(
[NNForegroundColorAttributeName: MixedColor.init(normal: UIColor.green, night: UIColor.red)],
range: NSRange(location: 0, length: 5)
)
label.attributedText = attributedString

How to modify tabbarItem text color

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

Carthage installation fails

Error message:

A shell task (/usr/bin/xcrun xcodebuild -project /Users/plu/Development/Poloniex-iOS/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/plu/Development/Poloniex-iOS/Carthage/Checkouts/NightNight/Example/Pods'.
	Reason: Project /Users/plu/Development/Poloniex-iOS/Carthage/Checkouts/NightNight/Example/Pods/Pods.xcodeproj cannot be opened because it is missing its project.pbxproj file.

Create Tag for v0.4.0

Please create a Tag for 0.4.0 version. CocoaPods can't see this version with Swift 3 update.

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!

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.

Delay in setting background color of collection view.

Everytime i toggle the theme and navigate to the home screen which is a collection view. it takes a second to apply the theme. how to instantly apply the theme to all the VCs at once.

I use this code in the collection view's cell MainArticleCell.appearance().mixedBackgroundColor = MixedColor(normal: kPBGNormal, night: kPBGDark)

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.

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.

Swift 4.2 support

Just asking when do you think NightNight will be compatible with Swift 4.2 ?

Thank's for your amazing job.

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

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.

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 ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.