All Projects → RayJiang16 → XYColor

RayJiang16 / XYColor

Licence: MIT license
An easy way to adapter dark mode on CALayer. iOS 快速适配夜间模式

Programming Languages

swift
15916 projects
python
139335 projects - #7 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to XYColor

ColorTranslator
A JavaScript library, written in TypeScript, to convert among different color models
Stars: ✭ 34 (-55.26%)
Mutual labels:  color
paper-terminal
Print Markdown to a paper in your terminal
Stars: ✭ 33 (-56.58%)
Mutual labels:  color
colour
Validate colours.
Stars: ✭ 31 (-59.21%)
Mutual labels:  color
pick-a-good-color
Choose the boldest and most accessible color for a given background.
Stars: ✭ 18 (-76.32%)
Mutual labels:  color
anypalette.js
🎨 Read/write all color palette file formats ❤🧡💛💚💙💜
Stars: ✭ 41 (-46.05%)
Mutual labels:  color
awesome-ios
A collaborative list of awesome for iOS developers. Include quick preview.
Stars: ✭ 1,329 (+1648.68%)
Mutual labels:  swift5
react-color
🎨 Is a tiny color picker widget component for React apps.
Stars: ✭ 50 (-34.21%)
Mutual labels:  color
Farge
🎈Tell the name of hex color
Stars: ✭ 23 (-69.74%)
Mutual labels:  color
pantone-colors
Hex values of all 2310 Pantone colors
Stars: ✭ 147 (+93.42%)
Mutual labels:  color
ColorBlender
A .NET library for color matching and palette design.
Stars: ✭ 27 (-64.47%)
Mutual labels:  color
Harbour
Docker/Portainer management app for iOS
Stars: ✭ 210 (+176.32%)
Mutual labels:  swift5
VideoTimelineView
Video timeline UI for iOS Apps
Stars: ✭ 103 (+35.53%)
Mutual labels:  swift5
StoreHelper
Implementing and testing In-App Purchases with StoreKit2 and StoreHelper in Xcode 13, Swift 5.5, SwiftUI, iOS 15 and macOS 12.
Stars: ✭ 158 (+107.89%)
Mutual labels:  swift5
sanzo-wada
🎨 Interactive version of Sanzo Wada's - "A Dictionary of Color Combinations"
Stars: ✭ 139 (+82.89%)
Mutual labels:  color
JetBrains-scheme
JetBrains主题,更完美的高亮。支持 IntelliJ IDEA、phpstorm、goland、webstorm
Stars: ✭ 25 (-67.11%)
Mutual labels:  color
nord-rofi-theme
An arctic, north-bluish clean and elegant rofi color theme.
Stars: ✭ 128 (+68.42%)
Mutual labels:  color
concolor
Colouring template strings using tags with annotations 🎨
Stars: ✭ 35 (-53.95%)
Mutual labels:  color
ansi-to-svg
😹 convert ANSI Escaped CLI strings to SVGs
Stars: ✭ 18 (-76.32%)
Mutual labels:  color
shape-color-dector
opencv检擦形状和颜色
Stars: ✭ 17 (-77.63%)
Mutual labels:  color
manakin
🐦 Prime colors for your Node.js console — quick & safe.
Stars: ✭ 29 (-61.84%)
Mutual labels:  color

XYColor

GitHub Actions CocoaPods Compatible Carthage Compatible Platform License

An easy way to adapter dark mode on CALayer

中文介绍

Requirements

  • iOS 8.0+
  • Swift 5.0+
  • Xcode 11.0+

Installation

Installation with CocoaPods:

  • Swift
pod 'XYColor'
  • Objective-C
pod 'XYColorOC'

Installation with Carthage:

github "RayJiang16/XYColor"

Run carthage to build the frameworks and drag the appropriate framework (XYColor.framework or XYColorOC.framework) into your Xcode project based on your need. Make sure to add only one framework and not both.

Usage

As we all known UIViewController and UIView has traitCollection.userInterfaceStyle property, but CALayer doesn't. Therefor CALayer wants to adapter dark mode, it need to bind on a UIView. That means CALayer will change color when UIView.traitCollection.userInterfaceStyle changed.

Swift

import XYColor

// View
private var customView: UIView = {
    let view = UIView()
    ...
    view.setLayerBorderColor(UIColor.label)
    view.setLayerShadowColor(UIColor.label)
    view.setLayerBackgroundColor(UIColor.systemBackground)
    ...
    return view
}()

// Layer
private var customLayer: CALayer = {
    let layer = CALayer()
    ...
    layer.setBorderColor(UIColor.label, with: customView)
    layer.setShadowColor(UIColor.label, with: customView)
    layer.setBackgroundColor(UIColor.systemBackground, with: customView)
    ...
    return layer
}()

// Create color
private var color: UIColor = {
    return UIColor.create(light: .black, dark: .white)
}()

Objective-C

#import "XYColorOC/XYColorOC.h"

// View
- (UIView *)customView {
    ...
    [_customView xy_setLayerBorderColor:UIColor.labelColor];
    [_customView xy_setLayerShadowColor:UIColor.labelColor];
    [_customView xy_setLayerBackgroundColor:UIColor.systemBackgroundColor];
    ...
}

// Layer
- (CALayer *)customLayer {
    ...
    [_customLayer xy_setLayerBorderColor:UIColor.labelColor with:self.customView];
    [_customLayer xy_setLayerShadowColor:UIColor.labelColor with:self.customView];
    [_customLayer xy_setLayerBackgroundColor:UIColor.systemBackgroundColor with:self.customView];
    ...
}

// Create color
- (UIColor *)color {
    if (!_color) {
        _color = [UIColor xy_createWithLightColor:UIColor.blackColor darkColor:UIColor.whiteColor];
    }
    return _color;
}

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].