Giter Site home page Giter Site logo

elenionl / easydarkmode Goto Github PK

View Code? Open in Web Editor NEW
152.0 4.0 16.0 1.71 MB

This is a tool for developers to easily adapt dark mode in iOS 13.

License: MIT License

Objective-C 57.00% Ruby 10.23% Swift 32.77%
darkmode-ios13 objective-c ios13 dark-theme dark-mode darkmode uitraitcollection

easydarkmode's Introduction

EasyDarkMode

version license platform Swfit Objective-C

Introduction

iOS 13 introduces user interface feature. This feature contains two kinds of user interface types, light and dark.

This project is a tool for developers to easily adapt user interface feature in iOS 13.

Star if you like it.

Samples

video

light

dark

Integrate with Cocoapods

Use this firm to find podfile script for your project.

Firstly, choose according to the language used in your project (Swift/Objective-C).

Secondly, choose according to whether you are using network image (Local image/Others).

Then, if you are using network image, choose the download method you preferred (SDWebImage/Kingfisher/Custom download method).

Podfile script Objective-C Swift Local image SDWebImage Kingfisher Custom download
pod 'EasyDarkMode' or pod 'EasyDarkMode/Core'
pod 'EasyDarkMode/Core-Swift'
pod 'EasyDarkMode/SDWebImage'
pod 'EasyDarkMode/SDWebImage+Swift'
pod 'EasyDarkMode/Kingfisher'
pod 'EasyDarkMode/Remote'
pod 'EasyDarkMode/Remote-Swift'

How to use

Create color with different user interface

  • Swift

Included in pod 'EasyDarkMode/Core-Swift'

import EasyDarkMode

view.backgroundColor = UIColor.dm.color(white:UIColor.black , dark: UIColor.white)
  • Objective-C

Included in pod 'EasyDarkMode/Core'

#import <EasyDarkMode/EasyDarkMode.h>

view.backgroundColor = [UIColor dm_colorWithColorLight:UIColor.grayColor dark:UIColor.whiteColor];

Create image from local with different user interface

  • Swift

Included in pod 'EasyDarkMode/Core-Swift'

import EasyDarkMode

imageView.image = UIImage.dm.image(name: "check_light", dark: "check_dark")
  • Objective-C

Included in pod 'EasyDarkMode/Core'

#import <EasyDarkMode/EasyDarkMode.h>

imageView.image = [UIImage dm_imageWithNameLight:@"check_light" dark:@""check_dark""];

Create image from SDWebImage with different user interface

  • Swift

Included in pod 'EasyDarkMode/SDWebImage+Swift'

import EasyDarkMode
// You should config downloder once before start to download images.
DMDownloadManager.shared.connectWithSdWebImage()
// ...
item.dm.setImage(pathString: "http://img.mp.itc.cn/upload/20160525/73e975795bf94f82baf43315f89a30b1_th.jpg", dark: "http://img.mp.itc.cn/upload/20160525/5d6588b3c928495a9ee0eb2b0b672936_th.jpg", for: UIControl.State.normal)
  • Objective-C

Included in pod 'EasyDarkMode/SDWebImage'

#import <EasyDarkMode/EasyDrakMode.h>
// You should config downloder once before start to download images.
[DMDownloadManager.shared connectWithSdWebImage];
// ...
[button dm_setImagePathStringLight:@"http://img.mp.itc.cn/upload/20160525/73e975795bf94f82baf43315f89a30b1_th.jpg" dark:@"http://img.mp.itc.cn/upload/20160525/5d6588b3c928495a9ee0eb2b0b672936_th.jpg" forState:UIControlStateNnormal];

Create image from Kingfisher with different user interface

  • Swift

Included in pod 'EasyDarkMode/Kingfisher'

import EasyDarkMode
// You should config downloder once before start to download images.
DMDownloadManager.shared.connectWithKingfisher()
// ...
item.dm.setImage(pathString: "http://img.mp.itc.cn/upload/20160525/73e975795bf94f82baf43315f89a30b1_th.jpg", dark: "http://img.mp.itc.cn/upload/20160525/5d6588b3c928495a9ee0eb2b0b672936_th.jpg", for: UIControl.State.normal)

Create image from custom download method with different user interface

  • Swift

Included in pod 'EasyDarkMode/Remote-Swift'

import EasyDarkMode
// You should config downloder once before start to download images.
DMDownloadManager.shared.downloader = { (url, completion) in
    // ...
}
// ...
item.dm.setImage(pathString: "http://img.mp.itc.cn/upload/20160525/73e975795bf94f82baf43315f89a30b1_th.jpg", dark: "http://img.mp.itc.cn/upload/20160525/5d6588b3c928495a9ee0eb2b0b672936_th.jpg", for: UIControl.State.normal)
  • Objective-C

Included in pod 'EasyDarkMode/Remote'

#import <EasyDarkMode/EasyDrakMode.h>
// You should config downloder once before start to download images.
DMDownloadManager.shared.downloader = ^(NSURL * _Nonnull data, DMDownloadHandler  _Nonnull completion) {
    // ...
}
// ...
[button dm_setImagePathStringLight:@"http://img.mp.itc.cn/upload/20160525/73e975795bf94f82baf43315f89a30b1_th.jpg" dark:@"http://img.mp.itc.cn/upload/20160525/5d6588b3c928495a9ee0eb2b0b672936_th.jpg" forState:UIControlStateNnormal];

Features

  • Shortcut method to create UIColor with different user interface type.

  • Shortcut method to create UIImage with different user interface type.

  • Written in Objective-C. All functions available in Swift with modern APIs.

  • Shortcut method to download remoate image with SDWebImage and Kingfisher and create UIImage with different user interface type.

  • This code can work on from Xcode 9 to Xcode 11.

  • It has an various deployment target version from iOS 8 to iOS 13.

  • We found that enable appearence image set in xcassets leads to dramatic lagging in application startup. Some walkaround like combine images into one UIImage object manually is necessory, if you are working with a giant application.

TODO

[●] Support UIImage/UIColor

[●] Support SDWebImage

[●] Support KingFisher.

[○] Find a way to support NSTextAttachment in NSAttributedString.

[○] Find a way to support web image for NSTextAttachment.

easydarkmode's People

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

easydarkmode's Issues

Kingfisher deployment target

Hi, would be nice to update to the latest Kingfisher, if possible

EasyDarkMode has
s.platform = :ios, "8.0"
but latests Kingfisher
s.ios.deployment_target = "10.0"

and connectWithKingfisher method will be needed to update.
Thanks :)

丢失UIImage对象的scale属性

UITraitCollection *lightCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight];
UITraitCollection *darkCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark];
UITraitCollection *unspecified = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleUnspecified];
UIImage *image = UIImage.new;
[image.imageAsset registerImage:light withTraitCollection:lightCollection];
[image.imageAsset registerImage:dark withTraitCollection:darkCollection];
UIImage *newImage = [[image.imageAsset imageWithTraitCollection:unspecified] copy];
[newImage.imageAsset registerImage:[image.imageAsset imageWithTraitCollection:lightCollection] withTraitCollection:lightCollection];
[newImage.imageAsset registerImage:[image.imageAsset imageWithTraitCollection:darkCollection] withTraitCollection:darkCollection];

这种方式会丢失UIImage对象的scale属性使获取图片的size出现问题,使用UITraitCollection对象前应该先与当前的[UITraitCollection currentTraitCollection]进行一次合并。

UITraitCollection *const scaleTraitCollection = [UITraitCollection currentTraitCollection];

UITraitCollection *const lightUnscaledTraitCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleLight];
UITraitCollection *const darkUnscaledTraitCollection = [UITraitCollection traitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark];
    
UITraitCollection *const lightScaledTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[scaleTraitCollection, lightUnscaledTraitCollection]];
UITraitCollection *const darkScaledTraitCollection = [UITraitCollection traitCollectionWithTraitsFromCollections:@[scaleTraitCollection, darkUnscaledTraitCollection]];

reference:
programmatic-dynamic-images

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.