├── .gitignore ├── .swift-version ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── DKNightVersion.framework.zip ├── DKNightVersion.podspec ├── DKNightVersion.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcshareddata │ └── xcschemes │ └── DKNightVersion.xcscheme ├── DKNightVersion.xcworkspace └── contents.xcworkspacedata ├── DKNightVersion ├── ColorTable │ ├── DKColorTable.h │ ├── DKColorTable.m │ └── DKColorTable.txt ├── Core │ ├── DKAlpha.h │ ├── DKAlpha.m │ ├── DKColor.h │ ├── DKColor.m │ ├── DKImage.h │ ├── DKImage.m │ ├── DKNightVersionManager.h │ ├── DKNightVersionManager.m │ ├── NSObject+Night.h │ └── NSObject+Night.m ├── CoreAnimation │ ├── CALayer+Night.h │ ├── CALayer+Night.m │ ├── CAShapeLayer+Night.h │ ├── CAShapeLayer+Night.m │ └── CoreAnimation+Night.h ├── DKNightVersion.h ├── DeallocBlockExecutor │ ├── DKDeallocBlockExecutor.h │ ├── DKDeallocBlockExecutor.m │ ├── NSObject+DeallocBlock.h │ └── NSObject+DeallocBlock.m ├── Info.plist ├── Manual │ ├── UIButton+Night.h │ ├── UIButton+Night.m │ ├── UIImageView+Night.h │ ├── UIImageView+Night.m │ ├── UINavigationBar+Animation.h │ ├── UINavigationBar+Animation.m │ ├── UISearchBar+Keyboard.h │ ├── UISearchBar+Keyboard.m │ ├── UITextField+Keyboard.h │ ├── UITextField+Keyboard.m │ ├── UITextView+Keyboard.h │ └── UITextView+Keyboard.m ├── UIKit │ ├── UIBarButtonItem+Night.h │ ├── UIBarButtonItem+Night.m │ ├── UIControl+Night.h │ ├── UIControl+Night.m │ ├── UILabel+Night.h │ ├── UILabel+Night.m │ ├── UINavigationBar+Night.h │ ├── UINavigationBar+Night.m │ ├── UIPageControl+Night.h │ ├── UIPageControl+Night.m │ ├── UIProgressView+Night.h │ ├── UIProgressView+Night.m │ ├── UISearchBar+Night.h │ ├── UISearchBar+Night.m │ ├── UISlider+Night.h │ ├── UISlider+Night.m │ ├── UISwitch+Night.h │ ├── UISwitch+Night.m │ ├── UITabBar+Night.h │ ├── UITabBar+Night.m │ ├── UITableView+Night.h │ ├── UITableView+Night.m │ ├── UITextField+Night.h │ ├── UITextField+Night.m │ ├── UITextView+Night.h │ ├── UITextView+Night.m │ ├── UIToolbar+Night.h │ ├── UIToolbar+Night.m │ ├── UIView+Night.h │ └── UIView+Night.m └── extobjc │ ├── EXTKeyPathCoding.h │ └── metamacros.h ├── EXTKeyPathCoding.h ├── Example ├── Example.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata └── Example │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ ├── Contents.json │ ├── night.imageset │ │ ├── Contents.json │ │ └── night.png │ ├── night1.imageset │ │ ├── Contents.json │ │ └── night1.png │ ├── normal.imageset │ │ ├── Contents.json │ │ └── normal.png │ └── normal1.imageset │ │ ├── Contents.json │ │ └── normal1.png │ ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard │ ├── Info.plist │ ├── PresentingViewController.h │ ├── PresentingViewController.m │ ├── RootViewController.h │ ├── RootViewController.m │ ├── SuccViewController.h │ ├── SuccViewController.m │ ├── TableViewCell.h │ ├── TableViewCell.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── README.md ├── Rakefile ├── fastlane ├── Fastfile ├── README.md └── actions │ ├── git_commit_all.rb │ └── sync_build_number_to_git.rb ├── generator └── lib │ ├── generator.rb │ └── generator │ ├── json │ ├── method.json │ ├── project.json │ └── superklass.json │ ├── model │ ├── objc_class.rb │ └── objc_property.rb │ ├── parser.rb │ ├── project.rb │ ├── render.rb │ ├── template │ ├── color.h.erb │ └── color.m.erb │ └── xcodeproj.rb ├── images ├── Banner.png ├── DKNightVersion.gif ├── add_file.png └── target.png ├── metamacros.h └── property.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | fastlane/report.xml 21 | 22 | # CocoaPods 23 | # 24 | # We recommend against adding the Pods directory to your .gitignore. However 25 | # you should judge for yourself, the pros and cons are mentioned at: 26 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 27 | # 28 | #Pods/ 29 | 30 | .DS_Store 31 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 3.0 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: objective-c 2 | os: osx 3 | osx_image: xcode8.3 4 | xcode_project: DKNightVersion.xcodeproj 5 | xcode_scheme: DKNightVersion 6 | rvm: 7 | - ruby-2.4.0 8 | before_install: 9 | - export LANG=en_US.UTF-8 10 | - gem install cocoapods 11 | - brew update 12 | - brew outdated carthage || brew upgrade carthage 13 | before_deploy: 14 | - carthage build --no-skip-current 15 | - carthage archive DKNightVersion 16 | script: 17 | - pod lib lint 18 | deploy: 19 | provider: releases 20 | api_key: 21 | secure: ytNR/5Dv829ymx1GQVK1Iv/UpJzz0YkbCehjL+lAp2x8Tex0SmXKPZF1pOs43gV8R2iPYcajvdGqS9EaeP9vEq2Fwea+X5+8tD07nqLAJQ1PqxTbsuLYaNMhKb8x05n7m7/Y8IOUTlTa3enc1px4dkbqVi/9GfXOyqR4Vnvcp7U= 22 | file: DKNightVersion.framework.zip 23 | skip_clean: true 24 | on: 25 | repo: Draveness/DKNightVersion 26 | tags: true 27 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at i@draveness.me. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /DKNightVersion.framework.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/draveness/DKNightVersion/a59ad0b5a9b4c15ba18f3bae30c2f61e542f2970/DKNightVersion.framework.zip -------------------------------------------------------------------------------- /DKNightVersion.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "DKNightVersion" 3 | s.version = "2.4.3" 4 | s.summary = "DKNightVersion is a lightweight iOS framework adding different theme to your iOS app." 5 | s.description = <<-DESC 6 | DKNightVersion is a light weight framework. It is mainly built through `objc/runtime` library and reflection, providing a neat approach adding night mode to your iOS app. A great many codes of this framework is automatically generated by Ruby script. 7 | 8 | The most delightful feature of DKNightVersion is that it provides a DKColorTable.txt file to help you manage all the colors in your project. It is easily-used and well-designed. Hope you have a great joy to use DKNightVersion to integrate night mode in your Apps. 9 | DESC 10 | s.homepage = "https://github.com/Draveness/DKNightVersion" 11 | s.license = "MIT" 12 | s.author = { "Draveness" => "stark.draven@gmail.com" } 13 | s.platform = :ios, "7.0" 14 | s.requires_arc = true 15 | s.source = { :git => "https://github.com/Draveness/DKNightVersion.git", :tag => s.version } 16 | s.source_files = "DKNightVersion/DKNightVersion.h" 17 | 18 | s.public_header_files = "DKNightVersion/DKNightVersion.h" 19 | s.resource = "DKNightVersion/ColorTable/DKColorTable.txt" 20 | 21 | s.subspec 'Core' do |ss| 22 | ss.source_files = "DKNightVersion/Core/*.{h,m}", "DKNightVersion/ColorTable/*{h,m}" 23 | 24 | ss.subspec 'DeallocBlockExecutor' do |sss| 25 | sss.source_files = "DKNightVersion/DeallocBlockExecutor/*.{h,m}" 26 | end 27 | 28 | ss.subspec 'extobjc' do |sss| 29 | sss.source_files = "DKNightVersion/extobjc/*.h" 30 | end 31 | 32 | end 33 | 34 | s.subspec 'UIKit' do |ss| 35 | ss.source_files = "DKNightVersion/UIKit/*.{h,m}", "DKNightVersion/Manual/*.{h,m}" 36 | ss.dependency 'DKNightVersion/Core' 37 | end 38 | 39 | s.subspec 'CoreAnimation' do |ss| 40 | ss.source_files = "DKNightVersion/CoreAnimation/*.{h,m}" 41 | ss.dependency 'DKNightVersion/Core' 42 | end 43 | 44 | end 45 | -------------------------------------------------------------------------------- /DKNightVersion.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DKNightVersion.xcodeproj/xcshareddata/xcschemes/DKNightVersion.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 59 | 60 | 61 | 62 | 63 | 64 | 70 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /DKNightVersion.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /DKNightVersion/ColorTable/DKColorTable.h: -------------------------------------------------------------------------------- 1 | // 2 | // DKColorTable.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/12/11. 6 | // Copyright © 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "DKNightVersionManager.h" 11 | 12 | /** 13 | * A convinient macro to create DKColorPicker block. 14 | * 15 | * @param key Key for corresponding entry in table 16 | * 17 | * @return DKColorPicker 18 | */ 19 | #define DKColorPickerWithKey(key) [[DKColorTable sharedColorTable] pickerWithKey:@#key] 20 | 21 | /** 22 | * DKColorTable is a new feature in 2.x, which providing you a very convinient and 23 | * delightful approach to manage all your color in an iOS project. Besides that, we 24 | * support multiple themes with DKColorTable, change your `DKColorTable.txt` file 25 | * like this: 26 | * 27 | * Ex: 28 | * 29 | * NORMAL NIGHT RED 30 | * #ffffff #343434 #ff0000 BG 31 | * #aaaaaa #313131 #ff0000 SEP 32 | * 33 | * And you can directly change `[DKNightVersionManager sharedManager].themeVersion` to 34 | * what you want, like: `RED` `NORMAL` and `NIGHT`. And trigger to post notification 35 | * and update corresponding color. 36 | */ 37 | @interface DKColorTable : NSObject 38 | 39 | /** 40 | * Call `- reloadColorTable` will trigger `DKColorTable` to load this file, 41 | * default is `DKColorTable.txt`. Don't need to call `- reloadColorTable` after 42 | * setting this property, cuz we have already do it for you. 43 | */ 44 | @property (nonatomic, strong) NSString *file; 45 | 46 | /** 47 | * An array of DKThemeVersion, order is exactly the same in `file`. 48 | */ 49 | @property (nonatomic, strong, readonly) NSArray *themes; 50 | 51 | /** 52 | * Return color table instance, you MUST use this method instead of `- init`, 53 | * `- init` method may have negative impact on your performance. 54 | * 55 | * @return An instance of DKColorTable 56 | */ 57 | + (instancetype)sharedColorTable; 58 | 59 | /** 60 | * Reload `file` into memory, and reconstrcut the whole color table. This method 61 | * will clear color table and use current `file` to load color table again. 62 | */ 63 | - (void)reloadColorTable; 64 | 65 | /** 66 | * Return a `DKColorPicker` with `key`, but I suggest you use marcho `DKColorPickerWithKey(key)` 67 | * instead of calling this method. 68 | * 69 | * Ex: 70 | * 71 | * NORMAL NIGHT 72 | * #ffffff #343434 BG 73 | * #aaaaaa #313131 SEP 74 | * 75 | * self.view.dk_backgroundColorPicker = DKColorPickerWithKey(BG); 76 | * 77 | * If current themeVersion is NORMAL, view's background color will be set to #ffffff. When theme 78 | * changes, it will automatically reload color from global color table and update current color 79 | * again. 80 | * 81 | * @param key Which indicates the entry you refer to 82 | * 83 | * @return An DKColorPicker block 84 | */ 85 | - (DKColorPicker)pickerWithKey:(NSString *)key; 86 | 87 | @end 88 | -------------------------------------------------------------------------------- /DKNightVersion/ColorTable/DKColorTable.m: -------------------------------------------------------------------------------- 1 | // 2 | // DKColorTable.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/12/11. 6 | // Copyright © 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import "DKColorTable.h" 10 | 11 | @interface NSString (Trimming) 12 | 13 | @end 14 | 15 | @implementation NSString (Trimming) 16 | 17 | - (NSString *)stringByTrimmingTrailingCharactersInSet:(NSCharacterSet *)characterSet { 18 | NSUInteger location = 0; 19 | NSUInteger length = [self length]; 20 | unichar charBuffer[length]; 21 | [self getCharacters:charBuffer]; 22 | 23 | for (; length > 0; length--) { 24 | if (![characterSet characterIsMember:charBuffer[length - 1]]) { 25 | break; 26 | } 27 | } 28 | 29 | return [self substringWithRange:NSMakeRange(location, length - location)]; 30 | } 31 | 32 | @end 33 | 34 | @interface DKColorTable () 35 | 36 | @property (nonatomic, strong) NSMutableDictionary *> *table; 37 | @property (nonatomic, strong, readwrite) NSArray *themes; 38 | 39 | @end 40 | 41 | @implementation DKColorTable 42 | 43 | UIColor *DKColorFromRGB(NSUInteger hex) { 44 | return [UIColor colorWithRed:((CGFloat)((hex >> 16) & 0xFF)/255.0) green:((CGFloat)((hex >> 8) & 0xFF)/255.0) blue:((CGFloat)(hex & 0xFF)/255.0) alpha:1.0]; 45 | } 46 | 47 | UIColor *DKColorFromRGBA(NSUInteger hex) { 48 | return [UIColor colorWithRed:((CGFloat)((hex >> 24) & 0xFF)/255.0) green:((CGFloat)((hex >> 16) & 0xFF)/255.0) blue:((CGFloat)((hex >> 8) & 0xFF)/255.0) alpha:((CGFloat)(hex & 0xFF)/255.0)]; 49 | } 50 | 51 | + (instancetype)sharedColorTable { 52 | static DKColorTable *sharedInstance = nil; 53 | static dispatch_once_t oncePredicate; 54 | dispatch_once(&oncePredicate, ^{ 55 | sharedInstance = [[DKColorTable alloc] init]; 56 | sharedInstance.file = @"DKColorTable.txt"; 57 | }); 58 | return sharedInstance; 59 | } 60 | 61 | - (void)reloadColorTable { 62 | // Clear previos color table 63 | self.table = nil; 64 | self.themes = nil; 65 | 66 | // Load color table file 67 | NSString *filepath = [[NSBundle mainBundle] pathForResource:self.file.stringByDeletingPathExtension ofType:self.file.pathExtension]; 68 | NSError *error; 69 | NSString *fileContents = [NSString stringWithContentsOfFile:filepath 70 | encoding:NSUTF8StringEncoding 71 | error:&error]; 72 | 73 | if (error) 74 | NSLog(@"Error reading file: %@", error.localizedDescription); 75 | 76 | NSLog(@"DKColorTable:\n%@", fileContents); 77 | 78 | 79 | NSMutableArray *tempEntries = [[fileContents componentsSeparatedByString:@"\n"] mutableCopy]; 80 | 81 | // Fixed whitespace error in txt file, fix https://github.com/Draveness/DKNightVersion/issues/64 82 | NSMutableArray *entries = [[NSMutableArray alloc] init]; 83 | [tempEntries enumerateObjectsUsingBlock:^(NSString * _Nonnull entry, NSUInteger idx, BOOL * _Nonnull stop) { 84 | NSString *trimmingEntry = [entry stringByTrimmingTrailingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 85 | [entries addObject:trimmingEntry]; 86 | }]; 87 | [entries filterUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]]; 88 | 89 | [entries removeObjectAtIndex:0]; // Remove theme entry 90 | 91 | self.themes = [self themesFromContents:fileContents]; 92 | 93 | // Add entry to color table 94 | for (NSString *entry in entries) { 95 | NSArray *colors = [self colorsFromEntry:entry]; 96 | NSString *keys = [self keyFromEntry:entry]; 97 | 98 | [self addEntryWithKey:keys colors:colors themes:self.themes]; 99 | } 100 | } 101 | 102 | - (NSArray *)themesFromContents:(NSString *)content { 103 | NSString *rawThemes = [content componentsSeparatedByString:@"\n"].firstObject; 104 | return [self separateString:rawThemes]; 105 | } 106 | 107 | - (NSArray *)colorsFromEntry:(NSString *)entry { 108 | NSMutableArray *colors = [[self separateString:entry] mutableCopy]; 109 | [colors removeLastObject]; 110 | NSMutableArray *result = [@[] mutableCopy]; 111 | for (NSString *number in colors) { 112 | [result addObject:[self colorFromString:number]]; 113 | } 114 | return result; 115 | } 116 | 117 | - (NSString *)keyFromEntry:(NSString *)entry { 118 | return [self separateString:entry].lastObject; 119 | } 120 | 121 | - (void)addEntryWithKey:(NSString *)key colors:(NSArray *)colors themes:(NSArray *)themes { 122 | NSParameterAssert(themes.count == colors.count); 123 | 124 | __block NSMutableDictionary *themeToColorDictionary = [@{} mutableCopy]; 125 | 126 | [themes enumerateObjectsUsingBlock:^(NSString * _Nonnull theme, NSUInteger idx, BOOL * _Nonnull stop) { 127 | [themeToColorDictionary setValue:colors[idx] forKey:theme]; 128 | }]; 129 | 130 | [self.table setValue:themeToColorDictionary forKey:key]; 131 | } 132 | 133 | - (DKColorPicker)pickerWithKey:(NSString *)key { 134 | NSParameterAssert(key); 135 | 136 | NSDictionary *themeToColorDictionary = [self.table valueForKey:key]; 137 | DKColorPicker picker = ^(DKThemeVersion *themeVersion) { 138 | return [themeToColorDictionary valueForKey:themeVersion]; 139 | }; 140 | return picker; 141 | 142 | } 143 | 144 | #pragma mark - Getter/Setter 145 | 146 | - (NSMutableDictionary *)table { 147 | if (!_table) { 148 | _table = [[NSMutableDictionary alloc] init]; 149 | } 150 | return _table; 151 | } 152 | 153 | - (void)setFile:(NSString *)file { 154 | _file = file; 155 | [self reloadColorTable]; 156 | } 157 | 158 | #pragma mark - Helper 159 | 160 | - (UIColor*)colorFromString:(NSString*)hexStr { 161 | hexStr = [hexStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 162 | if([hexStr hasPrefix:@"0x"]) { 163 | hexStr = [hexStr substringFromIndex:2]; 164 | } 165 | if([hexStr hasPrefix:@"#"]) { 166 | hexStr = [hexStr substringFromIndex:1]; 167 | } 168 | 169 | NSUInteger hex = [self intFromHexString:hexStr]; 170 | if(hexStr.length > 6) { 171 | return DKColorFromRGBA(hex); 172 | } 173 | 174 | return DKColorFromRGB(hex); 175 | } 176 | 177 | - (NSUInteger)intFromHexString:(NSString *)hexStr { 178 | unsigned int hexInt = 0; 179 | 180 | NSScanner *scanner = [NSScanner scannerWithString:hexStr]; 181 | 182 | [scanner scanHexInt:&hexInt]; 183 | 184 | return hexInt; 185 | } 186 | 187 | - (NSArray *)separateString:(NSString *)string { 188 | NSArray *array = [string componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; 189 | return [array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]]; 190 | } 191 | 192 | @end 193 | -------------------------------------------------------------------------------- /DKNightVersion/ColorTable/DKColorTable.txt: -------------------------------------------------------------------------------- 1 | NORMAL NIGHT RED 2 | #ffffff #343434 #fafafa BG 3 | #aaaaaa #313131 #aaaaaa SEP 4 | #0000ff #ffffff #fa0000 TINT 5 | #000000 #ffffff #000000 TEXT 6 | #ffffff #444444 #ffffff BAR 7 | #f0f0f0 #222222 #dedede HIGHLIGHTED 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /DKNightVersion/Core/DKAlpha.h: -------------------------------------------------------------------------------- 1 | // 2 | // DKAlpha.h 3 | // DKNightVersion 4 | // 5 | // Created by History on 16/12/10. 6 | // Copyright © 2016年 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NSString DKThemeVersion; 12 | 13 | typedef CGFloat (^DKAlphaPicker)(DKThemeVersion *themeVersion); 14 | 15 | DKAlphaPicker DKAlphaPickerWithAlphas(CGFloat normal, ...); 16 | 17 | @interface DKAlpha : NSObject 18 | 19 | + (DKAlphaPicker)alphaPickerWithAlpha:(CGFloat)alpha; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /DKNightVersion/Core/DKAlpha.m: -------------------------------------------------------------------------------- 1 | // 2 | // DKAlpha.m 3 | // DKNightVersion 4 | // 5 | // Created by History on 16/12/10. 6 | // Copyright © 2016年 Draveness. All rights reserved. 7 | // 8 | 9 | #import "DKAlpha.h" 10 | #import "DKNightVersionManager.h" 11 | #import "DKColorTable.h" 12 | 13 | DKAlphaPicker DKAlphaPickerWithAlphas(CGFloat normal, ...) { 14 | NSArray *themes = [DKColorTable sharedColorTable].themes; 15 | NSMutableArray *alphas = [[NSMutableArray alloc] initWithCapacity:themes.count]; 16 | [alphas addObject:@(normal)]; 17 | NSUInteger num_args = themes.count - 1; 18 | va_list args; 19 | #pragma clang diagnostic push 20 | #pragma clang diagnostic ignored "-Wvarargs" 21 | va_start(args, num_args); 22 | #pragma clang diagnostic pop 23 | for (NSUInteger i = 0; i < num_args; i++) { 24 | double alpha = va_arg(args, double); 25 | [alphas addObject:@(alpha)]; 26 | } 27 | va_end(args); 28 | 29 | return ^(DKThemeVersion *themeVersion) { 30 | NSUInteger index = [themes indexOfObject:themeVersion]; 31 | return (CGFloat)[alphas[index] floatValue]; 32 | }; 33 | } 34 | 35 | 36 | @implementation DKAlpha 37 | 38 | + (DKAlphaPicker)alphaPickerWithAlpha:(CGFloat)alpha { 39 | return ^(DKThemeVersion *themeVersion) { 40 | return alpha; 41 | }; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /DKNightVersion/Core/DKColor.h: -------------------------------------------------------------------------------- 1 | // 2 | // DKColor.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/12/9. 6 | // Copyright © 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NSString DKThemeVersion; 12 | 13 | typedef UIColor *(^DKColorPicker)(DKThemeVersion *themeVersion); 14 | 15 | DKColorPicker DKColorPickerWithRGB(NSUInteger normal, ...); 16 | DKColorPicker DKColorPickerWithColors(UIColor *normalColor, ...); 17 | 18 | @interface DKColor : NSObject 19 | 20 | + (DKColorPicker)colorPickerWithUIColor:(UIColor *)color; 21 | 22 | + (DKColorPicker)colorPickerWithWhite:(CGFloat)white alpha:(CGFloat)alpha; 23 | + (DKColorPicker)colorPickerWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha; 24 | + (DKColorPicker)colorPickerWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha; 25 | + (DKColorPicker)colorPickerWithCGColor:(CGColorRef)cgColor; 26 | + (DKColorPicker)colorPickerWithPatternImage:(UIImage *)image; 27 | #if __has_include() 28 | + (DKColorPicker)colorPickerWithCIColor:(CIColor *)ciColor NS_AVAILABLE_IOS(5_0); 29 | #endif 30 | 31 | + (DKColorPicker)blackColor; 32 | + (DKColorPicker)darkGrayColor; 33 | + (DKColorPicker)lightGrayColor; 34 | + (DKColorPicker)whiteColor; 35 | + (DKColorPicker)grayColor; 36 | + (DKColorPicker)redColor; 37 | + (DKColorPicker)greenColor; 38 | + (DKColorPicker)blueColor; 39 | + (DKColorPicker)cyanColor; 40 | + (DKColorPicker)yellowColor; 41 | + (DKColorPicker)magentaColor; 42 | + (DKColorPicker)orangeColor; 43 | + (DKColorPicker)purpleColor; 44 | + (DKColorPicker)brownColor; 45 | + (DKColorPicker)clearColor; 46 | 47 | @end 48 | -------------------------------------------------------------------------------- /DKNightVersion/Core/DKColor.m: -------------------------------------------------------------------------------- 1 | // 2 | // DKColor.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/12/9. 6 | // Copyright © 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import "DKColor.h" 10 | #import "DKNightVersionManager.h" 11 | #import "DKColorTable.h" 12 | 13 | @implementation DKColor 14 | 15 | DKColorPicker DKColorPickerWithRGB(NSUInteger normal, ...) { 16 | UIColor *normalColor = [UIColor colorWithRed:((float)((normal & 0xFF0000) >> 16))/255.0 green:((float)((normal & 0xFF00) >> 8))/255.0 blue:((float)(normal & 0xFF))/255.0 alpha:1.0]; 17 | 18 | NSArray *themes = [DKColorTable sharedColorTable].themes; 19 | NSMutableArray *colors = [[NSMutableArray alloc] initWithCapacity:themes.count]; 20 | [colors addObject:normalColor]; 21 | NSUInteger num_args = themes.count - 1; 22 | va_list rgbs; 23 | #pragma clang diagnostic push 24 | #pragma clang diagnostic ignored "-Wvarargs" 25 | va_start(rgbs, num_args); 26 | #pragma clang diagnostic pop 27 | for (NSUInteger i = 0; i < num_args; i++) { 28 | NSUInteger rgb = va_arg(rgbs, NSUInteger); 29 | UIColor *color = [UIColor colorWithRed:((float)((rgb & 0xFF0000) >> 16))/255.0 green:((float)((rgb & 0xFF00) >> 8))/255.0 blue:((float)(rgb & 0xFF))/255.0 alpha:1.0]; 30 | [colors addObject:color]; 31 | } 32 | va_end(rgbs); 33 | 34 | return ^(DKThemeVersion *themeVersion) { 35 | NSUInteger index = [themes indexOfObject:themeVersion]; 36 | return colors[index]; 37 | }; 38 | } 39 | 40 | DKColorPicker DKColorPickerWithColors(UIColor *normalColor, ...) { 41 | NSArray *themes = [DKColorTable sharedColorTable].themes; 42 | NSMutableArray *colors = [[NSMutableArray alloc] initWithCapacity:themes.count]; 43 | [colors addObject:normalColor]; 44 | NSUInteger num_args = themes.count - 1; 45 | va_list colors_list; 46 | #pragma clang diagnostic push 47 | #pragma clang diagnostic ignored "-Wvarargs" 48 | va_start(colors_list, num_args); 49 | #pragma clang diagnostic pop 50 | 51 | for (NSUInteger i = 0; i < num_args; i++) { 52 | UIColor *color = va_arg(colors_list, UIColor *); 53 | [colors addObject:color]; 54 | } 55 | va_end(colors_list); 56 | 57 | return ^(DKThemeVersion *themeVersion) { 58 | NSUInteger index = [themes indexOfObject:themeVersion]; 59 | return colors[index]; 60 | }; 61 | } 62 | 63 | + (DKColorPicker)pickerWithNormalColor:(UIColor *)normalColor nightColor:(UIColor *)nightColor { 64 | return ^(DKThemeVersion *themeVersion) { 65 | return [themeVersion isEqualToString:DKThemeVersionNormal] ? normalColor : nightColor; 66 | }; 67 | } 68 | 69 | + (DKColorPicker)colorPickerWithUIColor:(UIColor *)color { 70 | return ^(DKThemeVersion *themeVersion) { 71 | return color; 72 | }; 73 | } 74 | 75 | + (DKColorPicker)blackColor { 76 | return [self colorPickerWithUIColor:[UIColor blackColor]]; 77 | } 78 | 79 | + (DKColorPicker)darkGrayColor { 80 | return [self colorPickerWithUIColor:[UIColor darkGrayColor]]; 81 | } 82 | 83 | + (DKColorPicker)lightGrayColor { 84 | return [self colorPickerWithUIColor:[UIColor lightGrayColor]]; 85 | } 86 | 87 | + (DKColorPicker)whiteColor { 88 | return [self colorPickerWithUIColor:[UIColor whiteColor]]; 89 | } 90 | 91 | + (DKColorPicker)grayColor { 92 | return [self colorPickerWithUIColor:[UIColor grayColor]]; 93 | } 94 | 95 | + (DKColorPicker)redColor { 96 | return [self colorPickerWithUIColor:[UIColor redColor]]; 97 | } 98 | 99 | + (DKColorPicker)greenColor { 100 | return [self colorPickerWithUIColor:[UIColor greenColor]]; 101 | } 102 | 103 | + (DKColorPicker)blueColor { 104 | return [self colorPickerWithUIColor:[UIColor blueColor]]; 105 | } 106 | 107 | + (DKColorPicker)cyanColor { 108 | return [self colorPickerWithUIColor:[UIColor cyanColor]]; 109 | } 110 | 111 | + (DKColorPicker)yellowColor { 112 | return [self colorPickerWithUIColor:[UIColor yellowColor]]; 113 | } 114 | 115 | + (DKColorPicker)magentaColor { 116 | return [self colorPickerWithUIColor:[UIColor magentaColor]]; 117 | } 118 | 119 | + (DKColorPicker)orangeColor { 120 | return [self colorPickerWithUIColor:[UIColor orangeColor]]; 121 | } 122 | 123 | + (DKColorPicker)purpleColor { 124 | return [self colorPickerWithUIColor:[UIColor purpleColor]]; 125 | } 126 | 127 | + (DKColorPicker)brownColor { 128 | return [self colorPickerWithUIColor:[UIColor brownColor]]; 129 | } 130 | 131 | + (DKColorPicker)clearColor { 132 | return [self colorPickerWithUIColor:[UIColor clearColor]]; 133 | } 134 | 135 | + (DKColorPicker)colorPickerWithWhite:(CGFloat)white alpha:(CGFloat)alpha { 136 | return [self colorPickerWithUIColor:[UIColor colorWithWhite:white alpha:alpha]]; 137 | } 138 | 139 | + (DKColorPicker)colorPickerWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha { 140 | return [self colorPickerWithUIColor:[UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:alpha]]; 141 | } 142 | 143 | + (DKColorPicker)colorPickerWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha { 144 | return [self colorPickerWithUIColor:[UIColor colorWithRed:red green:green blue:blue alpha:alpha]]; 145 | } 146 | 147 | + (DKColorPicker)colorPickerWithCGColor:(CGColorRef)cgColor { 148 | return [self colorPickerWithUIColor:[UIColor colorWithCGColor:cgColor]]; 149 | } 150 | 151 | + (DKColorPicker)colorPickerWithPatternImage:(UIImage *)image { 152 | return [self colorPickerWithUIColor:[UIColor colorWithPatternImage:image]]; 153 | } 154 | 155 | #if __has_include() 156 | + (DKColorPicker)colorPickerWithCIColor:(CIColor *)ciColor NS_AVAILABLE_IOS(5_0) { 157 | return [self colorPickerWithUIColor:[UIColor colorWithCIColor:ciColor]]; 158 | } 159 | #endif 160 | 161 | @end 162 | 163 | -------------------------------------------------------------------------------- /DKNightVersion/Core/DKImage.h: -------------------------------------------------------------------------------- 1 | // 2 | // DKImage.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/12/10. 6 | // Copyright © 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | typedef NSString DKThemeVersion; 12 | 13 | typedef UIImage *(^DKImagePicker)(DKThemeVersion *themeVersion); 14 | 15 | /** 16 | * A C function takes an array of images return a image picker, the 17 | * order of the images is just like the themes order in DKColorTable.txt 18 | * file. 19 | * 20 | * @param normalImage Image when current themeVersion is DKThemeVersionNormal 21 | * @param ... Other images, the order is the same as DKColorTable 22 | * 23 | * @return A DKImagePicker 24 | */ 25 | DKImagePicker DKImagePickerWithImages(UIImage *normalImage, ...); 26 | 27 | /** 28 | * A C function takes an array of names return a image picker, the 29 | * order of the images is just like the themes order in DKColorTable.txt 30 | * file. 31 | * 32 | * @param normalName Names when current themeVersion is DKThemeVersionNormal 33 | * @param ... Other names, the order is the same as DKColorTable 34 | * 35 | * @return A DKImagePicker 36 | */ 37 | DKImagePicker DKImagePickerWithNames(NSString *normalName, ...); 38 | 39 | @interface DKImage : NSObject 40 | 41 | /** 42 | * A method takes an array of images return a image picker, the 43 | * order of the images is just like the themes order in DKColorTable.txt 44 | * file. 45 | * 46 | * @param names An array of images 47 | * 48 | * @return A DKImagePicker 49 | */ 50 | + (DKImagePicker)pickerWithNames:(NSArray *)names; 51 | 52 | /** 53 | * A method takes an array of images return a image picker, the 54 | * order of the images is just like the themes order in DKColorTable.txt 55 | * file. 56 | * 57 | * @param images An array of image names 58 | * 59 | * @return A DKImagePicker 60 | */ 61 | + (DKImagePicker)pickerWithImages:(NSArray *)images; 62 | 63 | /** 64 | * Returns a image picker return the same image no matter what the current 65 | * theme version is 66 | * 67 | * @param name The name for image 68 | * 69 | * @return A DKImagePicker 70 | */ 71 | + (DKImagePicker)imageNamed:(NSString *)name; 72 | 73 | /** 74 | * Returns a image picker return night image when current theme version is 75 | * DKThemeVersionNight, return normal image in other cases. 76 | * 77 | * @param normalImage Normal image 78 | * @param nightImage Image returns when theme version is DKThemeVersionNight 79 | * 80 | * @return A DKImagePicker 81 | */ 82 | + (DKImagePicker)pickerWithNormalImage:(UIImage *)normalImage nightImage:(UIImage *)nightImage; 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /DKNightVersion/Core/DKImage.m: -------------------------------------------------------------------------------- 1 | // 2 | // DKImage.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/12/10. 6 | // Copyright © 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import "DKImage.h" 10 | #import "DKNightVersionManager.h" 11 | #import "DKColorTable.h" 12 | 13 | @implementation DKImage 14 | 15 | DKImagePicker DKImagePickerWithNames(NSString *normalName, ...) { 16 | NSArray *themes = [DKColorTable sharedColorTable].themes; 17 | NSMutableArray *names = [[NSMutableArray alloc] initWithCapacity:themes.count]; 18 | [names addObject:normalName]; 19 | NSUInteger num_args = themes.count - 1; 20 | va_list names_list; 21 | #pragma clang diagnostic push 22 | #pragma clang diagnostic ignored "-Wvarargs" 23 | va_start(names_list, num_args); 24 | #pragma clang diagnostic pop 25 | for (NSUInteger i = 0; i < num_args; i++) { 26 | NSString *name = va_arg(names_list, NSString *); 27 | [names addObject:name]; 28 | } 29 | va_end(names_list); 30 | 31 | return [DKImage pickerWithNames:names]; 32 | } 33 | 34 | DKImagePicker DKImagePickerWithImages(UIImage *normalImage, ...) { 35 | NSArray *themes = [DKColorTable sharedColorTable].themes; 36 | NSMutableArray *images = [[NSMutableArray alloc] initWithCapacity:themes.count]; 37 | [images addObject:normalImage]; 38 | NSUInteger num_args = themes.count - 1; 39 | va_list images_list; 40 | #pragma clang diagnostic push 41 | #pragma clang diagnostic ignored "-Wvarargs" 42 | va_start(images_list, num_args); 43 | #pragma clang diagnostic pop 44 | for (NSUInteger i = 0; i < num_args; i++) { 45 | UIImage *image = va_arg(images_list, UIImage *); 46 | [images addObject:image]; 47 | } 48 | va_end(images_list); 49 | 50 | return [DKImage pickerWithImages:images]; 51 | } 52 | 53 | + (DKImagePicker)pickerWithNormalImage:(UIImage *)normalImage nightImage:(UIImage *)nightImage { 54 | NSParameterAssert(normalImage); 55 | NSParameterAssert(nightImage); 56 | return ^(DKThemeVersion *themeVersion) { 57 | return [themeVersion isEqualToString:DKThemeVersionNight] ? nightImage : normalImage; 58 | }; 59 | } 60 | 61 | + (DKImagePicker)pickerWithImage:(UIImage *)image { 62 | return ^(DKThemeVersion *themeVersion) { 63 | return image; 64 | }; 65 | } 66 | 67 | + (DKImagePicker)imageNamed:(NSString *)name { 68 | return [self pickerWithImage:[UIImage imageNamed:name]]; 69 | } 70 | 71 | + (DKImagePicker)pickerWithNames:(NSArray *)names { 72 | DKColorTable *colorTable = [DKColorTable sharedColorTable]; 73 | NSParameterAssert(names.count == colorTable.themes.count); 74 | return ^(DKThemeVersion *themeVersion) { 75 | NSUInteger index = [colorTable.themes indexOfObject:themeVersion]; 76 | if (index >= colorTable.themes.count) { 77 | return [UIImage imageNamed:names[[colorTable.themes indexOfObject:DKThemeVersionNormal]]]; 78 | } 79 | return [UIImage imageNamed:names[index]]; 80 | }; 81 | } 82 | 83 | + (DKImagePicker)pickerWithImages:(NSArray *)images { 84 | DKColorTable *colorTable = [DKColorTable sharedColorTable]; 85 | NSParameterAssert(images.count == colorTable.themes.count); 86 | return ^(DKThemeVersion *themeVersion) { 87 | NSUInteger index = [colorTable.themes indexOfObject:themeVersion]; 88 | if (index >= colorTable.themes.count) { 89 | return images[[colorTable.themes indexOfObject:DKThemeVersionNormal]]; 90 | } 91 | return images[index]; 92 | }; 93 | } 94 | 95 | @end 96 | -------------------------------------------------------------------------------- /DKNightVersion/Core/DKNightVersionManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // DKNightVersionManager.h 3 | // DKNightVersionManager 4 | // 5 | // Created by Draveness on 4/14/15. 6 | // Copyright (c) 2015 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "DKColor.h" 11 | #import "DKImage.h" 12 | #import "DKAlpha.h" 13 | 14 | NS_ASSUME_NONNULL_BEGIN 15 | 16 | /** 17 | * DKThemeVersion is just a alias to string, use `- isEqualToString` to 18 | * compare with each `DKThemeVersion` instead of symbol `==`. 19 | */ 20 | typedef NSString DKThemeVersion; 21 | 22 | /** 23 | * DKThemeVersionNormal is just a const string @"NORMAL", but use `- isEqualToString:` 24 | * to compare with another string. 25 | */ 26 | extern DKThemeVersion * const DKThemeVersionNormal; 27 | 28 | /** 29 | * DKThemeVersionNight is just a const string @"NIGHT", but use `- isEqualToString:` 30 | * to compare with another string. 31 | */ 32 | extern DKThemeVersion * const DKThemeVersionNight; 33 | 34 | /** 35 | * This notification will post, every time you change current theme version 36 | * of DKNightVersionManager glbal instance. 37 | */ 38 | extern NSString * const DKNightVersionThemeChangingNotification; 39 | 40 | /** 41 | * When change theme version, it will gives us a smooth animation. And this 42 | * is the duration for this animation. 43 | */ 44 | extern CGFloat const DKNightVersionAnimationDuration; 45 | 46 | /** 47 | * DKNightVersionManager is the core class for DKNightVersion, it manages all 48 | * the different themes in the color table. Use `- sharedInstance` instead of 49 | * `- init` to get an instance. 50 | */ 51 | @interface DKNightVersionManager : NSObject 52 | 53 | /** 54 | * if `changeStatusBar` is set to `YES`, the status bar will change to `UIStatusBarStyleLightContent` when invoke `+ nightFalling` and `UIStatusBarStyleDefault` for `+ dawnComing`. if you would like to use `-[UIViewController preferredStatusBarStyle]`, set this value to `NO`. Default to `YES` 55 | */ 56 | @property (nonatomic, assign, getter=shouldChangeStatusBar) BOOL changeStatusBar; 57 | 58 | /** 59 | * Current ThemeVersion, default is DKThemeVersionNormal, change it to change the global 60 | * theme, this will post `DKNightVersionThemeChangingNotification`, if you want to customize 61 | * your theme you can observe this notification. 62 | * 63 | * Ex: 64 | * 65 | * ```objectivec 66 | * DKNightVersionManager *manager = [DKNightVersionManager sharedManager]; 67 | * manager.themeVersion = @"RED"; // DKThemeVersionNormal or DKThemeVersionNight 68 | * ``` 69 | * 70 | */ 71 | @property (nonatomic, strong) DKThemeVersion *themeVersion; 72 | 73 | /** 74 | * Support keyboard type changes when swiching to DKThemeNight. If this value is YES, 75 | * `keyboardType` for UITextField will change to `UIKeyboardAppearanceDark` only current theme 76 | * version is DKThemeNight. Default is YES. 77 | */ 78 | @property (nonatomic, assign) BOOL supportsKeyboard; 79 | 80 | /** 81 | * Return the shared night version manager instance 82 | * 83 | * @return singleton instance for DKNightVersionManager 84 | */ 85 | + (DKNightVersionManager *)sharedManager; 86 | 87 | /** 88 | * Night falling. When nightFalling is called, post `DKNightVersionThemeChangingNotification`. 89 | * You can setup customize with observing the notification. `themeVersion` of the manager will 90 | * be set to `DKNightVersionNight`. This is a convinient method for switching theme the 91 | * `DKThemeVersionNight`. 92 | */ 93 | - (void)nightFalling; 94 | 95 | /** 96 | * Dawn coming. When dawnComing is called, post `DKNightVersionThemeChangingNotification`. 97 | * You can setup customize with observing the notification.`themeVersion` of the manager will 98 | * be set to `DKNightVersionNormal`. This is a convinient method for switching theme the 99 | * `DKThemeVersionNormal`. 100 | */ 101 | - (void)dawnComing; 102 | 103 | /** 104 | * This method is deprecated, use `- [DKNightVersion sharedManager]` instead 105 | */ 106 | + (DKNightVersionManager *)sharedNightVersionManager __deprecated_msg("use `- [DKNightVersion sharedManager]` instead"); 107 | 108 | @end 109 | 110 | NS_ASSUME_NONNULL_END 111 | -------------------------------------------------------------------------------- /DKNightVersion/Core/DKNightVersionManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // DKNightVersionManager.m 3 | // DKNightVersionManager 4 | // 5 | // Created by Draveness on 4/14/15. 6 | // Copyright (c) 2015 Draveness. All rights reserved. 7 | // 8 | 9 | #import "DKNightVersionManager.h" 10 | 11 | NSString * const DKThemeVersionNormal = @"NORMAL"; 12 | NSString * const DKThemeVersionNight = @"NIGHT"; 13 | 14 | NSString * const DKNightVersionThemeChangingNotification = @"DKNightVersionThemeChangingNotification"; 15 | 16 | CGFloat const DKNightVersionAnimationDuration = 0.3; 17 | 18 | NSString * const DKNightVersionCurrentThemeVersionKey = @"com.dknightversion.manager.themeversion"; 19 | 20 | @interface DKNightVersionManager () 21 | 22 | @end 23 | 24 | @implementation DKNightVersionManager 25 | 26 | + (DKNightVersionManager *)sharedManager { 27 | static dispatch_once_t once; 28 | static DKNightVersionManager *instance; 29 | dispatch_once(&once, ^{ 30 | instance = [self new]; 31 | instance.changeStatusBar = YES; 32 | NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; 33 | DKThemeVersion *themeVersion = [userDefaults valueForKey:DKNightVersionCurrentThemeVersionKey]; 34 | themeVersion = themeVersion ?: DKThemeVersionNormal; 35 | instance.themeVersion = themeVersion; 36 | instance.supportsKeyboard = YES; 37 | }); 38 | return instance; 39 | } 40 | 41 | + (DKNightVersionManager *)sharedNightVersionManager { 42 | return [self sharedManager]; 43 | } 44 | 45 | - (void)nightFalling { 46 | self.themeVersion = DKThemeVersionNight; 47 | } 48 | 49 | - (void)dawnComing { 50 | self.themeVersion = DKThemeVersionNormal; 51 | } 52 | 53 | - (void)setThemeVersion:(DKThemeVersion *)themeVersion { 54 | if ([_themeVersion isEqualToString:themeVersion]) { 55 | // if type does not change, don't execute code below to enhance performance. 56 | return; 57 | } 58 | _themeVersion = themeVersion; 59 | 60 | // Save current theme version to user default 61 | [[NSUserDefaults standardUserDefaults] setValue:themeVersion forKey:DKNightVersionCurrentThemeVersionKey]; 62 | [[NSNotificationCenter defaultCenter] postNotificationName:DKNightVersionThemeChangingNotification 63 | object:nil]; 64 | 65 | if (self.shouldChangeStatusBar) { 66 | #pragma clang diagnostic push 67 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" 68 | if ([themeVersion isEqualToString:DKThemeVersionNight]) { 69 | [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent]; 70 | } else { 71 | [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault]; 72 | } 73 | #pragma clang diagnostic pop 74 | } 75 | } 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /DKNightVersion/Core/NSObject+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+Night.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/11/7. 6 | // Copyright © 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "DKNightVersionManager.h" 11 | 12 | @interface NSObject (Night) 13 | 14 | /** 15 | * Default global DKNightVersionManager, this property gives us a more 16 | * convinient way to access it. 17 | */ 18 | @property (nonatomic, strong, readonly) DKNightVersionManager *dk_manager; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /DKNightVersion/Core/NSObject+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+Night.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/11/7. 6 | // Copyright © 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import "NSObject+Night.h" 10 | #import "NSObject+DeallocBlock.h" 11 | #import 12 | 13 | static void *DKViewDeallocHelperKey; 14 | 15 | @interface NSObject () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation NSObject (Night) 22 | 23 | - (NSMutableDictionary *)pickers { 24 | NSMutableDictionary *pickers = objc_getAssociatedObject(self, @selector(pickers)); 25 | if (!pickers) { 26 | 27 | @autoreleasepool { 28 | // Need to removeObserver in dealloc 29 | if (objc_getAssociatedObject(self, &DKViewDeallocHelperKey) == nil) { 30 | __unsafe_unretained typeof(self) weakSelf = self; // NOTE: need to be __unsafe_unretained because __weak var will be reset to nil in dealloc 31 | id deallocHelper = [self addDeallocBlock:^{ 32 | [[NSNotificationCenter defaultCenter] removeObserver:weakSelf]; 33 | }]; 34 | objc_setAssociatedObject(self, &DKViewDeallocHelperKey, deallocHelper, OBJC_ASSOCIATION_ASSIGN); 35 | } 36 | } 37 | 38 | pickers = [[NSMutableDictionary alloc] init]; 39 | objc_setAssociatedObject(self, @selector(pickers), pickers, OBJC_ASSOCIATION_RETAIN_NONATOMIC); 40 | 41 | [[NSNotificationCenter defaultCenter] removeObserver:self name:DKNightVersionThemeChangingNotification object:nil]; 42 | 43 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(night_updateColor) name:DKNightVersionThemeChangingNotification object:nil]; 44 | } 45 | return pickers; 46 | } 47 | 48 | - (DKNightVersionManager *)dk_manager { 49 | return [DKNightVersionManager sharedManager]; 50 | } 51 | 52 | - (void)night_updateColor { 53 | [self.pickers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull selector, DKColorPicker _Nonnull picker, BOOL * _Nonnull stop) { 54 | SEL sel = NSSelectorFromString(selector); 55 | id result = picker(self.dk_manager.themeVersion); 56 | [UIView animateWithDuration:DKNightVersionAnimationDuration 57 | animations:^{ 58 | #pragma clang diagnostic push 59 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 60 | [self performSelector:sel withObject:result]; 61 | #pragma clang diagnostic pop 62 | }]; 63 | }]; 64 | } 65 | 66 | @end 67 | -------------------------------------------------------------------------------- /DKNightVersion/CoreAnimation/CALayer+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // CALayer+Night.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 16/1/29. 6 | // Copyright © 2016年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "NSObject+Night.h" 11 | 12 | @interface CALayer (Night) 13 | 14 | @property (nonatomic, copy) DKColorPicker dk_shadowColorPicker; 15 | @property (nonatomic, copy) DKColorPicker dk_borderColorPicker; 16 | @property (nonatomic, copy) DKColorPicker dk_backgroundColorPicker; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /DKNightVersion/CoreAnimation/CALayer+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // CALayer+Night.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 16/1/29. 6 | // Copyright © 2016年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import "CALayer+Night.h" 10 | #import 11 | 12 | @interface CALayer () 13 | 14 | @property (nonatomic, strong) NSMutableDictionary *pickers; 15 | 16 | @end 17 | 18 | @implementation CALayer (Night) 19 | 20 | - (DKColorPicker)dk_shadowColorPicker { 21 | return objc_getAssociatedObject(self, @selector(dk_shadowColorPicker)); 22 | } 23 | 24 | - (void)setDk_shadowColorPicker:(DKColorPicker)picker { 25 | objc_setAssociatedObject(self, @selector(dk_shadowColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 26 | self.shadowColor = picker(self.dk_manager.themeVersion).CGColor; 27 | [self.pickers setValue:[picker copy] forKey:NSStringFromSelector(@selector(setShadowColor:))]; 28 | } 29 | 30 | - (DKColorPicker)dk_borderColorPicker { 31 | return objc_getAssociatedObject(self, @selector(dk_borderColorPicker)); 32 | } 33 | 34 | - (void)setDk_borderColorPicker:(DKColorPicker)picker { 35 | objc_setAssociatedObject(self, @selector(dk_borderColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 36 | self.borderColor = picker(self.dk_manager.themeVersion).CGColor; 37 | [self.pickers setValue:[picker copy] forKey:NSStringFromSelector(@selector(setBorderColor:))]; 38 | } 39 | 40 | - (DKColorPicker)dk_backgroundColorPicker { 41 | return objc_getAssociatedObject(self, @selector(dk_backgroundColorPicker)); 42 | } 43 | 44 | - (void)setDk_backgroundColorPicker:(DKColorPicker)picker { 45 | objc_setAssociatedObject(self, @selector(dk_backgroundColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 46 | self.backgroundColor = picker(self.dk_manager.themeVersion).CGColor; 47 | [self.pickers setValue:[picker copy] forKey:NSStringFromSelector(@selector(setBackgroundColor:))]; 48 | } 49 | 50 | - (void)night_updateColor { 51 | [self.pickers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull selector, DKColorPicker _Nonnull picker, BOOL * _Nonnull stop) { 52 | CGColorRef result = picker(self.dk_manager.themeVersion).CGColor; 53 | [UIView animateWithDuration:DKNightVersionAnimationDuration 54 | animations:^{ 55 | #pragma clang diagnostic push 56 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 57 | if ([selector isEqualToString:NSStringFromSelector(@selector(setShadowColor:))]) { 58 | [self setShadowColor:result]; 59 | } else if ([selector isEqualToString:NSStringFromSelector(@selector(setBorderColor:))]) { 60 | [self setBorderColor:result]; 61 | } else if ([selector isEqualToString:NSStringFromSelector(@selector(setBackgroundColor:)) ]) { 62 | [self setBackgroundColor:result]; 63 | } 64 | #pragma clang diagnostic pop 65 | }]; 66 | }]; 67 | } 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /DKNightVersion/CoreAnimation/CAShapeLayer+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // CAShapeLayer+Night.h 3 | // tztMobileApp_HTSC 4 | // 5 | // Created by YeTao on 2016/11/15. 6 | // 7 | // 8 | 9 | #import 10 | #import "NSObject+Night.h" 11 | 12 | @interface CAShapeLayer (Night) 13 | 14 | @property (nonatomic, copy) DKColorPicker dk_strokeColorPicker; 15 | @property (nonatomic, copy) DKColorPicker dk_fillColorPicker; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /DKNightVersion/CoreAnimation/CAShapeLayer+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // CAShapeLayer+Night.m 3 | // tztMobileApp_HTSC 4 | // 5 | // Created by YeTao on 2016/11/15. 6 | // 7 | // 8 | 9 | #import "CAShapeLayer+Night.h" 10 | #import 11 | 12 | @interface CAShapeLayer () 13 | 14 | @property (nonatomic, strong) NSMutableDictionary *pickers; 15 | 16 | @end 17 | 18 | @implementation CAShapeLayer (Night) 19 | 20 | - (DKColorPicker)dk_strokeColorPicker { 21 | return objc_getAssociatedObject(self, @selector(dk_strokeColorPicker)); 22 | } 23 | 24 | - (void)setDk_strokeColorPicker:(DKColorPicker)picker { 25 | objc_setAssociatedObject(self, @selector(dk_strokeColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 26 | self.strokeColor = picker(self.dk_manager.themeVersion).CGColor; 27 | [self.pickers setValue:[picker copy] forKey:NSStringFromSelector(@selector(setStrokeColor:))]; 28 | } 29 | 30 | - (DKColorPicker)dk_fillColorPicker { 31 | return objc_getAssociatedObject(self, @selector(dk_strokeColorPicker)); 32 | } 33 | 34 | - (void)setDk_fillColorPicker:(DKColorPicker)picker { 35 | objc_setAssociatedObject(self, @selector(dk_fillColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 36 | self.fillColor = picker(self.dk_manager.themeVersion).CGColor; 37 | [self.pickers setValue:[picker copy] forKey:NSStringFromSelector(@selector(setFillColor:))]; 38 | } 39 | 40 | - (void)night_updateColor { 41 | [self.pickers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull selector, DKColorPicker _Nonnull picker, BOOL * _Nonnull stop) { 42 | CGColorRef result = picker(self.dk_manager.themeVersion).CGColor; 43 | [UIView animateWithDuration:DKNightVersionAnimationDuration 44 | animations:^{ 45 | #pragma clang diagnostic push 46 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 47 | if ([selector isEqualToString:NSStringFromSelector(@selector(setShadowColor:))]) { 48 | [self setShadowColor:result]; 49 | } else if ([selector isEqualToString:NSStringFromSelector(@selector(setBorderColor:))]) { 50 | [self setBorderColor:result]; 51 | } else if ([selector isEqualToString:NSStringFromSelector(@selector(setBackgroundColor:)) ]) { 52 | [self setBackgroundColor:result]; 53 | } else if ([selector isEqualToString:NSStringFromSelector(@selector(setStrokeColor:)) ]) { 54 | [self setStrokeColor:result]; 55 | } else if ([selector isEqualToString:NSStringFromSelector(@selector(setFillColor:)) ]) { 56 | [self setFillColor:result]; 57 | } 58 | #pragma clang diagnostic pop 59 | }]; 60 | }]; 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /DKNightVersion/CoreAnimation/CoreAnimation+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // CoreAnimation+Night.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 16/4/1. 6 | // Copyright © 2016年 DeltaX. All rights reserved. 7 | // 8 | 9 | #ifndef CoreAnimation_Night_h 10 | #define CoreAnimation_Night_h 11 | 12 | #import "CALayer+Night.h" 13 | 14 | #endif /* CoreAnimation_Night_h */ 15 | -------------------------------------------------------------------------------- /DKNightVersion/DKNightVersion.h: -------------------------------------------------------------------------------- 1 | // 2 | // DKNightVersion.h 3 | // DKNightVerision 4 | // 5 | // Created by Draveness on 4/14/15. 6 | // Copyright (c) 2015 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for DKNightVersion. 12 | FOUNDATION_EXPORT double DKNightVersionVersionNumber; 13 | 14 | //! Project version string for DKNightVersion. 15 | FOUNDATION_EXPORT const unsigned char DKNightVersionVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | #ifndef _DKNIGHTVERSION_ 20 | #define _DKNIGHTVERSION_ 21 | 22 | #import 23 | 24 | #import 25 | #import 26 | #import 27 | #import 28 | #import 29 | 30 | #import 31 | 32 | #import 33 | 34 | #import 35 | #import 36 | #import 37 | #import 38 | #import 39 | #import 40 | #import 41 | #import 42 | #import 43 | #import 44 | #import 45 | #import 46 | #import 47 | #import 48 | #import 49 | #import 50 | #import 51 | 52 | #import 53 | #import 54 | 55 | #define _DKSetterWithPROPERTYerty(LOWERCASE) [NSString stringWithFormat:@"set%@:", [[[LOWERCASE substringToIndex:1] uppercaseString] stringByAppendingString:[LOWERCASE substringFromIndex:1]]] 56 | 57 | #define pickerify(KLASS, PROPERTY) interface \ 58 | KLASS (Night_ ## PROPERTY ## _Picker) \ 59 | @property (nonatomic, copy, setter = dk_set ## PROPERTY ## Picker:) DKColorPicker dk_ ## PROPERTY ## Picker; \ 60 | @end \ 61 | @implementation \ 62 | KLASS (Night_ ## PROPERTY ## _Picker) \ 63 | - (DKColorPicker)dk_ ## PROPERTY ## Picker { \ 64 | return objc_getAssociatedObject(self, @selector(dk_ ## PROPERTY ## Picker)); \ 65 | } \ 66 | - (void)dk_set ## PROPERTY ## Picker:(DKColorPicker)picker { \ 67 | objc_setAssociatedObject(self, @selector(dk_ ## PROPERTY ## Picker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); \ 68 | [self setValue:picker(self.dk_manager.themeVersion) forKeyPath:@keypath(self, PROPERTY)];\ 69 | NSMutableDictionary *pickers = [self valueForKeyPath:@"pickers"];\ 70 | [pickers setValue:[picker copy] forKey:_DKSetterWithPROPERTYerty(@#PROPERTY)]; \ 71 | } \ 72 | @end 73 | 74 | 75 | #endif /* _DKNIGHTVERSION_ */ 76 | -------------------------------------------------------------------------------- /DKNightVersion/DeallocBlockExecutor/DKDeallocBlockExecutor.h: -------------------------------------------------------------------------------- 1 | // 2 | // DeallocBlockExecutor.h 3 | // DKNightVersion 4 | // 5 | // Created by nathanwhy on 16/2/24. 6 | // Copyright © 2016年 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface DKDeallocBlockExecutor : NSObject 12 | 13 | + (instancetype)executorWithDeallocBlock:(void (^)())deallocBlock; 14 | 15 | @property (nonatomic, copy) void (^deallocBlock)(); 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /DKNightVersion/DeallocBlockExecutor/DKDeallocBlockExecutor.m: -------------------------------------------------------------------------------- 1 | // 2 | // DeallocBlockExecutor.m 3 | // DKNightVersion 4 | // 5 | // Created by nathanwhy on 16/2/24. 6 | // Copyright © 2016年 Draveness. All rights reserved. 7 | // 8 | 9 | #import "DKDeallocBlockExecutor.h" 10 | 11 | @implementation DKDeallocBlockExecutor 12 | 13 | + (instancetype)executorWithDeallocBlock:(void (^)())deallocBlock { 14 | DKDeallocBlockExecutor *o = [DKDeallocBlockExecutor new]; 15 | o.deallocBlock = deallocBlock; 16 | return o; 17 | } 18 | 19 | - (void)dealloc { 20 | if (self.deallocBlock) { 21 | self.deallocBlock(); 22 | self.deallocBlock = nil; 23 | } 24 | } 25 | @end 26 | -------------------------------------------------------------------------------- /DKNightVersion/DeallocBlockExecutor/NSObject+DeallocBlock.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+DeallocBlock.h 3 | // DKNightVersion 4 | // 5 | // Created by nathanwhy on 16/2/24. 6 | // Copyright © 2016年 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSObject (DeallocBlock) 12 | 13 | - (id)addDeallocBlock:(void (^)())deallocBlock; 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /DKNightVersion/DeallocBlockExecutor/NSObject+DeallocBlock.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+DeallocBlock.m 3 | // DKNightVersion 4 | // 5 | // Created by nathanwhy on 16/2/24. 6 | // Copyright © 2016年 Draveness. All rights reserved. 7 | // 8 | 9 | #import "NSObject+DeallocBlock.h" 10 | #import "DKDeallocBlockExecutor.h" 11 | #import 12 | 13 | static void *kNSObject_DeallocBlocks; 14 | 15 | @implementation NSObject (DeallocBlock) 16 | 17 | - (id)addDeallocBlock:(void (^)())deallocBlock { 18 | if (deallocBlock == nil) { 19 | return nil; 20 | } 21 | 22 | NSMutableArray *deallocBlocks = objc_getAssociatedObject(self, &kNSObject_DeallocBlocks); 23 | if (deallocBlocks == nil) { 24 | deallocBlocks = [NSMutableArray array]; 25 | objc_setAssociatedObject(self, &kNSObject_DeallocBlocks, deallocBlocks, OBJC_ASSOCIATION_RETAIN); 26 | } 27 | // Check if the block is already existed 28 | for (DKDeallocBlockExecutor *executor in deallocBlocks) { 29 | if (executor.deallocBlock == deallocBlock) { 30 | return nil; 31 | } 32 | } 33 | 34 | DKDeallocBlockExecutor *executor = [DKDeallocBlockExecutor executorWithDeallocBlock:deallocBlock]; 35 | [deallocBlocks addObject:executor]; 36 | return executor; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /DKNightVersion/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 2.4.3 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 616 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /DKNightVersion/Manual/UIButton+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+Night.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/12/9. 6 | // Copyright © 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "NSObject+Night.h" 11 | 12 | @interface UIButton (Night) 13 | 14 | - (void)dk_setTitleColorPicker:(DKColorPicker)picker forState:(UIControlState)state; 15 | 16 | - (void)dk_setBackgroundImage:(DKImagePicker)picker forState:(UIControlState)state; 17 | 18 | - (void)dk_setImage:(DKImagePicker)picker forState:(UIControlState)state; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /DKNightVersion/Manual/UIButton+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIButton+Night.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/12/9. 6 | // Copyright © 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import "UIButton+Night.h" 10 | #import 11 | 12 | @interface UIButton () 13 | 14 | @property (nonatomic, strong) NSMutableDictionary *pickers; 15 | 16 | @end 17 | 18 | @implementation UIButton (Night) 19 | 20 | - (void)dk_setTitleColorPicker:(DKColorPicker)picker forState:(UIControlState)state { 21 | [self setTitleColor:picker(self.dk_manager.themeVersion) forState:state]; 22 | NSString *key = [NSString stringWithFormat:@"%@", @(state)]; 23 | NSMutableDictionary *dictionary = [self.pickers valueForKey:key]; 24 | if (!dictionary) { 25 | dictionary = [[NSMutableDictionary alloc] init]; 26 | } 27 | [dictionary setValue:[picker copy] forKey:NSStringFromSelector(@selector(setTitleColor:forState:))]; 28 | [self.pickers setValue:dictionary forKey:key]; 29 | } 30 | 31 | - (void)dk_setBackgroundImage:(DKImagePicker)picker forState:(UIControlState)state { 32 | [self setBackgroundImage:picker(self.dk_manager.themeVersion) forState:state]; 33 | NSString *key = [NSString stringWithFormat:@"%@", @(state)]; 34 | NSMutableDictionary *dictionary = [self.pickers valueForKey:key]; 35 | if (!dictionary) { 36 | dictionary = [[NSMutableDictionary alloc] init]; 37 | } 38 | [dictionary setValue:[picker copy] forKey:NSStringFromSelector(@selector(setBackgroundImage:forState:))]; 39 | [self.pickers setValue:dictionary forKey:key]; 40 | } 41 | 42 | - (void)dk_setImage:(DKImagePicker)picker forState:(UIControlState)state { 43 | [self setImage:picker(self.dk_manager.themeVersion) forState:state]; 44 | NSString *key = [NSString stringWithFormat:@"%@", @(state)]; 45 | NSMutableDictionary *dictionary = [self.pickers valueForKey:key]; 46 | if (!dictionary) { 47 | dictionary = [[NSMutableDictionary alloc] init]; 48 | } 49 | [dictionary setValue:[picker copy] forKey:NSStringFromSelector(@selector(setImage:forState:))]; 50 | [self.pickers setValue:dictionary forKey:key]; 51 | } 52 | 53 | - (void)night_updateColor { 54 | [self.pickers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { 55 | if ([obj isKindOfClass:[NSDictionary class]]) { 56 | NSDictionary *dictionary = (NSDictionary *)obj; 57 | [dictionary enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull selector, DKColorPicker _Nonnull picker, BOOL * _Nonnull stop) { 58 | UIControlState state = [key integerValue]; 59 | [UIView animateWithDuration:DKNightVersionAnimationDuration 60 | animations:^{ 61 | if ([selector isEqualToString:NSStringFromSelector(@selector(setTitleColor:forState:))]) { 62 | UIColor *resultColor = picker(self.dk_manager.themeVersion); 63 | [self setTitleColor:resultColor forState:state]; 64 | } else if ([selector isEqualToString:NSStringFromSelector(@selector(setBackgroundImage:forState:))]) { 65 | UIImage *resultImage = ((DKImagePicker)picker)(self.dk_manager.themeVersion); 66 | [self setBackgroundImage:resultImage forState:state]; 67 | } else if ([selector isEqualToString:NSStringFromSelector(@selector(setImage:forState:))]) { 68 | UIImage *resultImage = ((DKImagePicker)picker)(self.dk_manager.themeVersion); 69 | [self setImage:resultImage forState:state]; 70 | } 71 | }]; 72 | }]; 73 | } else { 74 | SEL sel = NSSelectorFromString(key); 75 | DKColorPicker picker = (DKColorPicker)obj; 76 | UIColor *resultColor = picker(self.dk_manager.themeVersion); 77 | [UIView animateWithDuration:DKNightVersionAnimationDuration 78 | animations:^{ 79 | #pragma clang diagnostic push 80 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 81 | [self performSelector:sel withObject:resultColor]; 82 | #pragma clang diagnostic pop 83 | }]; 84 | 85 | } 86 | }]; 87 | } 88 | 89 | @end 90 | -------------------------------------------------------------------------------- /DKNightVersion/Manual/UIImageView+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+Night.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/12/10. 6 | // Copyright © 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "DKNightVersionManager.h" 11 | 12 | NS_ASSUME_NONNULL_BEGIN 13 | 14 | @interface UIImageView (Night) 15 | 16 | - (instancetype)dk_initWithImagePicker:(DKImagePicker)picker; 17 | 18 | @property (nullable, nonatomic, copy, setter = dk_setImagePicker:) DKImagePicker dk_imagePicker; 19 | 20 | @property (nonatomic, copy, setter = dk_setAlphaPicker:) DKAlphaPicker dk_alphaPicker; 21 | 22 | @end 23 | 24 | NS_ASSUME_NONNULL_END 25 | -------------------------------------------------------------------------------- /DKNightVersion/Manual/UIImageView+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIImageView+Night.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/12/10. 6 | // Copyright © 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import "UIImageView+Night.h" 10 | #import "NSObject+Night.h" 11 | #import 12 | #import 13 | 14 | @interface NSObject () 15 | 16 | @property (nonatomic, strong) NSMutableDictionary *pickers; 17 | 18 | @end 19 | 20 | @implementation UIImageView (Night) 21 | 22 | - (instancetype)dk_initWithImagePicker:(DKImagePicker)picker { 23 | UIImageView *imageView = [self initWithImage:picker(self.dk_manager.themeVersion)]; 24 | imageView.dk_imagePicker = [picker copy]; 25 | return imageView; 26 | } 27 | 28 | - (DKImagePicker)dk_imagePicker { 29 | return objc_getAssociatedObject(self, @selector(dk_imagePicker)); 30 | } 31 | 32 | - (void)dk_setImagePicker:(DKImagePicker)picker { 33 | objc_setAssociatedObject(self, @selector(dk_imagePicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 34 | self.image = picker(self.dk_manager.themeVersion); 35 | [self.pickers setValue:[picker copy] forKey:@"setImage:"]; 36 | 37 | } 38 | 39 | - (DKAlphaPicker)dk_alphaPicker { 40 | return objc_getAssociatedObject(self, @selector(dk_alphaPicker)); 41 | } 42 | 43 | - (void)dk_setAlphaPicker:(DKAlphaPicker)picker { 44 | objc_setAssociatedObject(self, @selector(dk_alphaPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 45 | self.alpha = picker(self.dk_manager.themeVersion); 46 | [self.pickers setValue:[picker copy] forKey:@"setAlpha:"]; 47 | } 48 | 49 | - (void)night_updateColor { 50 | [self.pickers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { 51 | if ([key isEqualToString:@"setAlpha:"]) { 52 | DKAlphaPicker picker = (DKAlphaPicker)obj; 53 | CGFloat alpha = picker(self.dk_manager.themeVersion); 54 | [UIView animateWithDuration:DKNightVersionAnimationDuration 55 | animations:^{ 56 | ((void (*)(id, SEL, CGFloat))objc_msgSend)(self, NSSelectorFromString(key), alpha); 57 | }]; 58 | } else { 59 | SEL sel = NSSelectorFromString(key); 60 | DKColorPicker picker = (DKColorPicker)obj; 61 | UIColor *resultColor = picker(self.dk_manager.themeVersion); 62 | [UIView animateWithDuration:DKNightVersionAnimationDuration 63 | animations:^{ 64 | #pragma clang diagnostic push 65 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" 66 | [self performSelector:sel withObject:resultColor]; 67 | #pragma clang diagnostic pop 68 | }]; 69 | 70 | } 71 | }]; 72 | } 73 | 74 | @end 75 | -------------------------------------------------------------------------------- /DKNightVersion/Manual/UINavigationBar+Animation.h: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationBar+Animation.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/5/4. 6 | // Copyright (c) 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UINavigationBar (Animation) 12 | 13 | - (void)animateNavigationBarToColor:(UIColor *)toColor 14 | duration:(NSTimeInterval)duration; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /DKNightVersion/Manual/UINavigationBar+Animation.m: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationBar+Animation.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/5/4. 6 | // Copyright (c) 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import "UINavigationBar+Animation.h" 10 | 11 | CGFloat const stepDuration = 0.01; 12 | 13 | @implementation UINavigationBar (Animation) 14 | 15 | - (void)animateNavigationBarToColor:(UIColor *)toColor duration:(NSTimeInterval)duration { 16 | if (!self.barTintColor || !toColor) { 17 | return; 18 | } 19 | UIColor *barDefaultColor = [UIColor colorWithRed:0.973 green:0.973 blue:0.973 alpha:1.0]; 20 | 21 | UIColor *barTintColor = self.barTintColor ? : barDefaultColor; 22 | toColor = toColor ? : barDefaultColor; 23 | NSUInteger steps = duration / stepDuration; 24 | 25 | CGFloat fromRed, fromGreen, fromBlue, fromAlpha; 26 | CGFloat toRed, toGreen, toBlue, toAlpha; 27 | 28 | [barTintColor getRed:&fromRed green:&fromGreen blue:&fromBlue alpha:&fromAlpha]; 29 | [toColor getRed:&toRed green:&toGreen blue:&toBlue alpha:&toAlpha]; 30 | 31 | CGFloat diffRed = toRed - fromRed; 32 | CGFloat diffGreen = toGreen - fromGreen; 33 | CGFloat diffBlue = toBlue - fromBlue; 34 | CGFloat diffAlpha = toAlpha - fromAlpha; 35 | 36 | NSMutableArray *colorArray = [NSMutableArray array]; 37 | 38 | [colorArray addObject:barTintColor]; 39 | 40 | for (NSUInteger i = 0; i < steps - 1; ++i) { 41 | CGFloat red = fromRed + diffRed / steps * (i + 1); 42 | CGFloat green = fromGreen + diffGreen / steps * (i + 1); 43 | CGFloat blue = fromBlue + diffBlue / steps * (i + 1); 44 | CGFloat alpha = fromAlpha + diffAlpha / steps * (i + 1); 45 | 46 | UIColor *color = [UIColor colorWithRed:red green:green blue:blue alpha:alpha]; 47 | [colorArray addObject:color]; 48 | } 49 | 50 | [colorArray addObject:toColor]; 51 | [self animateWithArray:colorArray]; 52 | } 53 | 54 | - (void)animateWithArray:(NSMutableArray *)array { 55 | NSUInteger counter = 0; 56 | 57 | for (UIColor *color in array) { 58 | double delayInSeconds = stepDuration * counter++; 59 | dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); 60 | dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 61 | [UIView animateWithDuration:stepDuration animations:^{ 62 | self.barTintColor = color; 63 | }]; 64 | }); 65 | } 66 | } 67 | 68 | 69 | @end 70 | -------------------------------------------------------------------------------- /DKNightVersion/Manual/UISearchBar+Keyboard.h: -------------------------------------------------------------------------------- 1 | // 2 | // UISearchBar+Keyboard.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 6/8/16. 6 | // Copyright © 2016 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UISearchBar (Keyboard) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /DKNightVersion/Manual/UISearchBar+Keyboard.m: -------------------------------------------------------------------------------- 1 | // 2 | // UISearchBar+Keyboard.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 6/8/16. 6 | // Copyright © 2016 Draveness. All rights reserved. 7 | // 8 | 9 | #import "UISearchBar+Keyboard.h" 10 | #import "NSObject+Night.h" 11 | #import 12 | 13 | @interface NSObject () 14 | 15 | - (void)night_updateColor; 16 | 17 | @end 18 | 19 | @implementation UISearchBar (Keyboard) 20 | 21 | + (void)load { 22 | static dispatch_once_t onceToken; 23 | dispatch_once(&onceToken, ^{ 24 | Class class = [self class]; 25 | 26 | SEL originalSelector = @selector(init); 27 | SEL swizzledSelector = @selector(dk_init); 28 | 29 | Method originalMethod = class_getInstanceMethod(class, originalSelector); 30 | Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); 31 | 32 | BOOL didAddMethod = 33 | class_addMethod(class, 34 | originalSelector, 35 | method_getImplementation(swizzledMethod), 36 | method_getTypeEncoding(swizzledMethod)); 37 | 38 | if (didAddMethod) { 39 | class_replaceMethod(class, 40 | swizzledSelector, 41 | method_getImplementation(originalMethod), 42 | method_getTypeEncoding(originalMethod)); 43 | } else { 44 | method_exchangeImplementations(originalMethod, swizzledMethod); 45 | } 46 | }); 47 | 48 | } 49 | 50 | - (instancetype)dk_init { 51 | UISearchBar *obj = [self dk_init]; 52 | if (self.dk_manager.supportsKeyboard && [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) { 53 | 54 | #if defined(__IPHONE_13_0) 55 | UISearchTextField *searchField = obj.searchTextField; 56 | searchField.keyboardAppearance = UIKeyboardAppearanceDark; 57 | #elif defined(__IPHONE_7_0) 58 | UITextField *searchField = [obj valueForKey:@"_searchField"]; 59 | searchField.keyboardAppearance = UIKeyboardAppearanceDark; 60 | #else 61 | obj.keyboardAppearance = UIKeyboardAppearanceAlert; 62 | #endif 63 | } else { 64 | #if defined(__IPHONE_13_0) 65 | UISearchTextField *searchField = obj.searchTextField; 66 | searchField.keyboardAppearance = UIKeyboardAppearanceDefault; 67 | #elif defined(__IPHONE_7_0) 68 | UITextField *searchField = [obj valueForKey:@"_searchField"]; 69 | searchField.keyboardAppearance = UIKeyboardAppearanceDefault; 70 | #else 71 | obj.keyboardAppearance = UIKeyboardAppearanceDefault; 72 | #endif 73 | } 74 | 75 | return obj; 76 | } 77 | 78 | - (void)night_updateColor { 79 | [super night_updateColor]; 80 | if (self.dk_manager.supportsKeyboard && [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) { 81 | #if defined(__IPHONE_13_0) 82 | UISearchTextField *searchField = self.searchTextField; 83 | searchField.keyboardAppearance = UIKeyboardAppearanceDark; 84 | #elif defined(__IPHONE_7_0) 85 | UITextField *searchField = [self valueForKey:@"_searchField"]; 86 | searchField.keyboardAppearance = UIKeyboardAppearanceDark; 87 | #else 88 | self.keyboardAppearance = UIKeyboardAppearanceAlert; 89 | #endif 90 | } else { 91 | #if defined(__IPHONE_13_0) 92 | UISearchTextField *searchField = self.searchTextField; 93 | searchField.keyboardAppearance = UIKeyboardAppearanceDefault; 94 | #elif defined(__IPHONE_7_0) 95 | UITextField *searchField = [self valueForKey:@"_searchField"]; 96 | searchField.keyboardAppearance = UIKeyboardAppearanceDefault; 97 | #else 98 | self.keyboardAppearance = UIKeyboardAppearanceDefault; 99 | #endif 100 | } 101 | } 102 | 103 | @end 104 | -------------------------------------------------------------------------------- /DKNightVersion/Manual/UITextField+Keyboard.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+Keyboard.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 16/4/11. 6 | // Copyright © 2016年 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UITextField (Keyboard) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /DKNightVersion/Manual/UITextField+Keyboard.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+Keyboard.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 16/4/11. 6 | // Copyright © 2016年 Draveness. All rights reserved. 7 | // 8 | 9 | #import "UITextField+Keyboard.h" 10 | #import "NSObject+Night.h" 11 | #import 12 | 13 | @interface NSObject () 14 | 15 | - (void)night_updateColor; 16 | 17 | @end 18 | 19 | 20 | @implementation UITextField (Keyboard) 21 | 22 | + (void)load { 23 | static dispatch_once_t onceToken; 24 | dispatch_once(&onceToken, ^{ 25 | Class class = [self class]; 26 | 27 | SEL originalSelector = @selector(init); 28 | SEL swizzledSelector = @selector(dk_init); 29 | 30 | Method originalMethod = class_getInstanceMethod(class, originalSelector); 31 | Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); 32 | 33 | BOOL didAddMethod = 34 | class_addMethod(class, 35 | originalSelector, 36 | method_getImplementation(swizzledMethod), 37 | method_getTypeEncoding(swizzledMethod)); 38 | 39 | if (didAddMethod) { 40 | class_replaceMethod(class, 41 | swizzledSelector, 42 | method_getImplementation(originalMethod), 43 | method_getTypeEncoding(originalMethod)); 44 | } else { 45 | method_exchangeImplementations(originalMethod, swizzledMethod); 46 | } 47 | }); 48 | 49 | } 50 | 51 | - (instancetype)dk_init { 52 | UITextField *obj = [self dk_init]; 53 | if (self.dk_manager.supportsKeyboard && [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) { 54 | #ifdef __IPHONE_7_0 55 | obj.keyboardAppearance = UIKeyboardAppearanceDark; 56 | #else 57 | obj.keyboardAppearance = UIKeyboardAppearanceAlert; 58 | #endif 59 | } else { 60 | obj.keyboardAppearance = UIKeyboardAppearanceDefault; 61 | } 62 | return obj; 63 | } 64 | 65 | - (void)night_updateColor { 66 | [super night_updateColor]; 67 | if (self.dk_manager.supportsKeyboard && [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) { 68 | #ifdef __IPHONE_7_0 69 | self.keyboardAppearance = UIKeyboardAppearanceDark; 70 | #else 71 | self.keyboardAppearance = UIKeyboardAppearanceAlert; 72 | #endif 73 | } else { 74 | self.keyboardAppearance = UIKeyboardAppearanceDefault; 75 | } 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /DKNightVersion/Manual/UITextView+Keyboard.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITextView+Keyboard.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 6/5/16. 6 | // Copyright © 2016 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface UITextView (Keyboard) 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /DKNightVersion/Manual/UITextView+Keyboard.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITextView+Keyboard.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 6/5/16. 6 | // Copyright © 2016 Draveness. All rights reserved. 7 | // 8 | 9 | #import "UITextView+Keyboard.h" 10 | #import "NSObject+Night.h" 11 | #import 12 | 13 | @interface NSObject () 14 | 15 | - (void)night_updateColor; 16 | 17 | @end 18 | 19 | @implementation UITextView (Keyboard) 20 | 21 | + (void)load { 22 | static dispatch_once_t onceToken; 23 | dispatch_once(&onceToken, ^{ 24 | Class class = [self class]; 25 | 26 | SEL originalSelector = @selector(init); 27 | SEL swizzledSelector = @selector(dk_init); 28 | 29 | Method originalMethod = class_getInstanceMethod(class, originalSelector); 30 | Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); 31 | 32 | BOOL didAddMethod = 33 | class_addMethod(class, 34 | originalSelector, 35 | method_getImplementation(swizzledMethod), 36 | method_getTypeEncoding(swizzledMethod)); 37 | 38 | if (didAddMethod) { 39 | class_replaceMethod(class, 40 | swizzledSelector, 41 | method_getImplementation(originalMethod), 42 | method_getTypeEncoding(originalMethod)); 43 | } else { 44 | method_exchangeImplementations(originalMethod, swizzledMethod); 45 | } 46 | }); 47 | 48 | } 49 | 50 | - (instancetype)dk_init { 51 | UITextView *obj = [self dk_init]; 52 | if (self.dk_manager.supportsKeyboard && [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) { 53 | #ifdef __IPHONE_7_0 54 | obj.keyboardAppearance = UIKeyboardAppearanceDark; 55 | #else 56 | obj.keyboardAppearance = UIKeyboardAppearanceAlert; 57 | #endif 58 | } else { 59 | obj.keyboardAppearance = UIKeyboardAppearanceDefault; 60 | } 61 | return obj; 62 | } 63 | 64 | - (void)night_updateColor { 65 | [super night_updateColor]; 66 | if (self.dk_manager.supportsKeyboard && [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) { 67 | #ifdef __IPHONE_7_0 68 | self.keyboardAppearance = UIKeyboardAppearanceDark; 69 | #else 70 | self.keyboardAppearance = UIKeyboardAppearanceAlert; 71 | #endif 72 | } else { 73 | self.keyboardAppearance = UIKeyboardAppearanceDefault; 74 | } 75 | } 76 | 77 | @end 78 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UIBarButtonItem+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIBarButtonItem+Night.h 3 | // UIBarButtonItem+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UIBarButtonItem (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setTintColorPicker:) DKColorPicker dk_tintColorPicker; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UIBarButtonItem+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIBarButtonItem+Night.m 3 | // UIBarButtonItem+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UIBarButtonItem+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UIBarButtonItem () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UIBarButtonItem (Night) 22 | 23 | 24 | - (DKColorPicker)dk_tintColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_tintColorPicker)); 26 | } 27 | 28 | - (void)dk_setTintColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_tintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.tintColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setTintColor:"]; 32 | } 33 | 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UIControl+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIControl+Night.h 3 | // UIControl+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UIControl (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setTintColorPicker:) DKColorPicker dk_tintColorPicker; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UIControl+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIControl+Night.m 3 | // UIControl+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UIControl+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UIControl () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UIControl (Night) 22 | 23 | 24 | - (DKColorPicker)dk_tintColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_tintColorPicker)); 26 | } 27 | 28 | - (void)dk_setTintColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_tintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.tintColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setTintColor:"]; 32 | } 33 | 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UILabel+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UILabel+Night.h 3 | // UILabel+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UILabel (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setTextColorPicker:) DKColorPicker dk_textColorPicker; 17 | @property (nonatomic, copy, setter = dk_setShadowColorPicker:) DKColorPicker dk_shadowColorPicker; 18 | @property (nonatomic, copy, setter = dk_setHighlightedTextColorPicker:) DKColorPicker dk_highlightedTextColorPicker; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UILabel+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UILabel+Night.m 3 | // UILabel+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UILabel+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UILabel () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UILabel (Night) 22 | 23 | 24 | - (DKColorPicker)dk_textColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_textColorPicker)); 26 | } 27 | 28 | - (void)dk_setTextColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_textColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.textColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setTextColor:"]; 32 | } 33 | 34 | - (DKColorPicker)dk_shadowColorPicker { 35 | return objc_getAssociatedObject(self, @selector(dk_shadowColorPicker)); 36 | } 37 | 38 | - (void)dk_setShadowColorPicker:(DKColorPicker)picker { 39 | objc_setAssociatedObject(self, @selector(dk_shadowColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 40 | self.shadowColor = picker(self.dk_manager.themeVersion); 41 | [self.pickers setValue:[picker copy] forKey:@"setShadowColor:"]; 42 | } 43 | 44 | - (DKColorPicker)dk_highlightedTextColorPicker { 45 | return objc_getAssociatedObject(self, @selector(dk_highlightedTextColorPicker)); 46 | } 47 | 48 | - (void)dk_setHighlightedTextColorPicker:(DKColorPicker)picker { 49 | objc_setAssociatedObject(self, @selector(dk_highlightedTextColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 50 | self.highlightedTextColor = picker(self.dk_manager.themeVersion); 51 | [self.pickers setValue:[picker copy] forKey:@"setHighlightedTextColor:"]; 52 | } 53 | 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UINavigationBar+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationBar+Night.h 3 | // UINavigationBar+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UINavigationBar (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setBarTintColorPicker:) DKColorPicker dk_barTintColorPicker; 17 | @property (nonatomic, copy, setter = dk_setTintColorPicker:) DKColorPicker dk_tintColorPicker; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UINavigationBar+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UINavigationBar+Night.m 3 | // UINavigationBar+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UINavigationBar+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UINavigationBar () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UINavigationBar (Night) 22 | 23 | 24 | - (DKColorPicker)dk_barTintColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_barTintColorPicker)); 26 | } 27 | 28 | - (void)dk_setBarTintColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_barTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.barTintColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setBarTintColor:"]; 32 | } 33 | 34 | - (DKColorPicker)dk_tintColorPicker { 35 | return objc_getAssociatedObject(self, @selector(dk_tintColorPicker)); 36 | } 37 | 38 | - (void)dk_setTintColorPicker:(DKColorPicker)picker { 39 | objc_setAssociatedObject(self, @selector(dk_tintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 40 | self.tintColor = picker(self.dk_manager.themeVersion); 41 | [self.pickers setValue:[picker copy] forKey:@"setTintColor:"]; 42 | } 43 | 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UIPageControl+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIPageControl+Night.h 3 | // UIPageControl+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UIPageControl (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setPageIndicatorTintColorPicker:) DKColorPicker dk_pageIndicatorTintColorPicker; 17 | @property (nonatomic, copy, setter = dk_setCurrentPageIndicatorTintColorPicker:) DKColorPicker dk_currentPageIndicatorTintColorPicker; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UIPageControl+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIPageControl+Night.m 3 | // UIPageControl+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UIPageControl+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UIPageControl () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UIPageControl (Night) 22 | 23 | 24 | - (DKColorPicker)dk_pageIndicatorTintColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_pageIndicatorTintColorPicker)); 26 | } 27 | 28 | - (void)dk_setPageIndicatorTintColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_pageIndicatorTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.pageIndicatorTintColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setPageIndicatorTintColor:"]; 32 | } 33 | 34 | - (DKColorPicker)dk_currentPageIndicatorTintColorPicker { 35 | return objc_getAssociatedObject(self, @selector(dk_currentPageIndicatorTintColorPicker)); 36 | } 37 | 38 | - (void)dk_setCurrentPageIndicatorTintColorPicker:(DKColorPicker)picker { 39 | objc_setAssociatedObject(self, @selector(dk_currentPageIndicatorTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 40 | self.currentPageIndicatorTintColor = picker(self.dk_manager.themeVersion); 41 | [self.pickers setValue:[picker copy] forKey:@"setCurrentPageIndicatorTintColor:"]; 42 | } 43 | 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UIProgressView+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIProgressView+Night.h 3 | // UIProgressView+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UIProgressView (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setProgressTintColorPicker:) DKColorPicker dk_progressTintColorPicker; 17 | @property (nonatomic, copy, setter = dk_setTrackTintColorPicker:) DKColorPicker dk_trackTintColorPicker; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UIProgressView+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIProgressView+Night.m 3 | // UIProgressView+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UIProgressView+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UIProgressView () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UIProgressView (Night) 22 | 23 | 24 | - (DKColorPicker)dk_progressTintColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_progressTintColorPicker)); 26 | } 27 | 28 | - (void)dk_setProgressTintColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_progressTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.progressTintColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setProgressTintColor:"]; 32 | } 33 | 34 | - (DKColorPicker)dk_trackTintColorPicker { 35 | return objc_getAssociatedObject(self, @selector(dk_trackTintColorPicker)); 36 | } 37 | 38 | - (void)dk_setTrackTintColorPicker:(DKColorPicker)picker { 39 | objc_setAssociatedObject(self, @selector(dk_trackTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 40 | self.trackTintColor = picker(self.dk_manager.themeVersion); 41 | [self.pickers setValue:[picker copy] forKey:@"setTrackTintColor:"]; 42 | } 43 | 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UISearchBar+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UISearchBar+Night.h 3 | // UISearchBar+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UISearchBar (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setBarTintColorPicker:) DKColorPicker dk_barTintColorPicker; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UISearchBar+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UISearchBar+Night.m 3 | // UISearchBar+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UISearchBar+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UISearchBar () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UISearchBar (Night) 22 | 23 | 24 | - (DKColorPicker)dk_barTintColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_barTintColorPicker)); 26 | } 27 | 28 | - (void)dk_setBarTintColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_barTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.barTintColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setBarTintColor:"]; 32 | } 33 | 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UISlider+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UISlider+Night.h 3 | // UISlider+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UISlider (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setMinimumTrackTintColorPicker:) DKColorPicker dk_minimumTrackTintColorPicker; 17 | @property (nonatomic, copy, setter = dk_setMaximumTrackTintColorPicker:) DKColorPicker dk_maximumTrackTintColorPicker; 18 | @property (nonatomic, copy, setter = dk_setThumbTintColorPicker:) DKColorPicker dk_thumbTintColorPicker; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UISlider+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UISlider+Night.m 3 | // UISlider+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UISlider+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UISlider () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UISlider (Night) 22 | 23 | 24 | - (DKColorPicker)dk_minimumTrackTintColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_minimumTrackTintColorPicker)); 26 | } 27 | 28 | - (void)dk_setMinimumTrackTintColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_minimumTrackTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.minimumTrackTintColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setMinimumTrackTintColor:"]; 32 | } 33 | 34 | - (DKColorPicker)dk_maximumTrackTintColorPicker { 35 | return objc_getAssociatedObject(self, @selector(dk_maximumTrackTintColorPicker)); 36 | } 37 | 38 | - (void)dk_setMaximumTrackTintColorPicker:(DKColorPicker)picker { 39 | objc_setAssociatedObject(self, @selector(dk_maximumTrackTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 40 | self.maximumTrackTintColor = picker(self.dk_manager.themeVersion); 41 | [self.pickers setValue:[picker copy] forKey:@"setMaximumTrackTintColor:"]; 42 | } 43 | 44 | - (DKColorPicker)dk_thumbTintColorPicker { 45 | return objc_getAssociatedObject(self, @selector(dk_thumbTintColorPicker)); 46 | } 47 | 48 | - (void)dk_setThumbTintColorPicker:(DKColorPicker)picker { 49 | objc_setAssociatedObject(self, @selector(dk_thumbTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 50 | self.thumbTintColor = picker(self.dk_manager.themeVersion); 51 | [self.pickers setValue:[picker copy] forKey:@"setThumbTintColor:"]; 52 | } 53 | 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UISwitch+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UISwitch+Night.h 3 | // UISwitch+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UISwitch (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setOnTintColorPicker:) DKColorPicker dk_onTintColorPicker; 17 | @property (nonatomic, copy, setter = dk_setThumbTintColorPicker:) DKColorPicker dk_thumbTintColorPicker; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UISwitch+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UISwitch+Night.m 3 | // UISwitch+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UISwitch+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UISwitch () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UISwitch (Night) 22 | 23 | 24 | - (DKColorPicker)dk_onTintColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_onTintColorPicker)); 26 | } 27 | 28 | - (void)dk_setOnTintColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_onTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.onTintColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setOnTintColor:"]; 32 | } 33 | 34 | - (DKColorPicker)dk_thumbTintColorPicker { 35 | return objc_getAssociatedObject(self, @selector(dk_thumbTintColorPicker)); 36 | } 37 | 38 | - (void)dk_setThumbTintColorPicker:(DKColorPicker)picker { 39 | objc_setAssociatedObject(self, @selector(dk_thumbTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 40 | self.thumbTintColor = picker(self.dk_manager.themeVersion); 41 | [self.pickers setValue:[picker copy] forKey:@"setThumbTintColor:"]; 42 | } 43 | 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UITabBar+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITabBar+Night.h 3 | // UITabBar+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UITabBar (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setBarTintColorPicker:) DKColorPicker dk_barTintColorPicker; 17 | 18 | @property (nonatomic, copy, setter = dk_setBarBackgroundColorPicker:) DKColorPicker dk_barBackgroundColorPicker; 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UITabBar+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITabBar+Night.m 3 | // UITabBar+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UITabBar+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UITabBar () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UITabBar (Night) 22 | 23 | 24 | - (DKColorPicker)dk_barTintColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_barTintColorPicker)); 26 | } 27 | 28 | - (void)dk_setBarTintColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_barTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.barTintColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setBarTintColor:"]; 32 | } 33 | 34 | 35 | - (DKColorPicker)dk_barBackgroundColorPicker { 36 | return objc_getAssociatedObject(self, @selector(dk_barTintColorPicker)); 37 | } 38 | 39 | - (void)dk_setBarBackgroundColorPicker:(DKColorPicker)picker { 40 | objc_setAssociatedObject(self, @selector(dk_barTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 41 | self.tintColor = picker(self.dk_manager.themeVersion); 42 | [self.pickers setValue:[picker copy] forKey:@"setTintColor:"]; 43 | } 44 | 45 | 46 | @end 47 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UITableView+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+Night.h 3 | // UITableView+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UITableView (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setSeparatorColorPicker:) DKColorPicker dk_separatorColorPicker; 17 | @property (nonatomic, copy, setter = dk_setSectionIndexColorPicker:) DKColorPicker dk_sectionIndexColorPicker; 18 | @property (nonatomic, copy, setter = dk_setSectionIndexBackgroundColorPicker:) DKColorPicker dk_sectionIndexBackgroundColorPicker; 19 | @property (nonatomic, copy, setter = dk_setSectionIndexTrackingBackgroundColorPicker:) DKColorPicker dk_sectionIndexTrackingBackgroundColorPicker; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UITableView+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITableView+Night.m 3 | // UITableView+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UITableView+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UITableView () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UITableView (Night) 22 | 23 | 24 | - (DKColorPicker)dk_separatorColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_separatorColorPicker)); 26 | } 27 | 28 | - (void)dk_setSeparatorColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_separatorColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.separatorColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setSeparatorColor:"]; 32 | } 33 | 34 | - (DKColorPicker)dk_sectionIndexColorPicker { 35 | return objc_getAssociatedObject(self, @selector(dk_sectionIndexColorPicker)); 36 | } 37 | 38 | - (void)dk_setSectionIndexColorPicker:(DKColorPicker)picker { 39 | objc_setAssociatedObject(self, @selector(dk_sectionIndexColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 40 | self.sectionIndexColor = picker(self.dk_manager.themeVersion); 41 | [self.pickers setValue:[picker copy] forKey:@"setSectionIndexColor:"]; 42 | } 43 | 44 | - (DKColorPicker)dk_sectionIndexBackgroundColorPicker { 45 | return objc_getAssociatedObject(self, @selector(dk_sectionIndexBackgroundColorPicker)); 46 | } 47 | 48 | - (void)dk_setSectionIndexBackgroundColorPicker:(DKColorPicker)picker { 49 | objc_setAssociatedObject(self, @selector(dk_sectionIndexBackgroundColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 50 | self.sectionIndexBackgroundColor = picker(self.dk_manager.themeVersion); 51 | [self.pickers setValue:[picker copy] forKey:@"setSectionIndexBackgroundColor:"]; 52 | } 53 | 54 | - (DKColorPicker)dk_sectionIndexTrackingBackgroundColorPicker { 55 | return objc_getAssociatedObject(self, @selector(dk_sectionIndexTrackingBackgroundColorPicker)); 56 | } 57 | 58 | - (void)dk_setSectionIndexTrackingBackgroundColorPicker:(DKColorPicker)picker { 59 | objc_setAssociatedObject(self, @selector(dk_sectionIndexTrackingBackgroundColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 60 | self.sectionIndexTrackingBackgroundColor = picker(self.dk_manager.themeVersion); 61 | [self.pickers setValue:[picker copy] forKey:@"setSectionIndexTrackingBackgroundColor:"]; 62 | } 63 | 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UITextField+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+Night.h 3 | // UITextField+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UITextField (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setTextColorPicker:) DKColorPicker dk_textColorPicker; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UITextField+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITextField+Night.m 3 | // UITextField+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UITextField+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UITextField () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UITextField (Night) 22 | 23 | 24 | - (DKColorPicker)dk_textColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_textColorPicker)); 26 | } 27 | 28 | - (void)dk_setTextColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_textColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.textColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setTextColor:"]; 32 | } 33 | 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UITextView+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UITextView+Night.h 3 | // UITextView+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UITextView (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setTextColorPicker:) DKColorPicker dk_textColorPicker; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UITextView+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UITextView+Night.m 3 | // UITextView+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UITextView+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UITextView () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UITextView (Night) 22 | 23 | 24 | - (DKColorPicker)dk_textColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_textColorPicker)); 26 | } 27 | 28 | - (void)dk_setTextColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_textColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.textColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setTextColor:"]; 32 | } 33 | 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UIToolbar+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIToolbar+Night.h 3 | // UIToolbar+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UIToolbar (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setBarTintColorPicker:) DKColorPicker dk_barTintColorPicker; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UIToolbar+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIToolbar+Night.m 3 | // UIToolbar+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UIToolbar+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UIToolbar () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UIToolbar (Night) 22 | 23 | 24 | - (DKColorPicker)dk_barTintColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_barTintColorPicker)); 26 | } 27 | 28 | - (void)dk_setBarTintColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_barTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.barTintColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setBarTintColor:"]; 32 | } 33 | 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UIView+Night.h: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Night.h 3 | // UIView+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface UIView (Night) 15 | 16 | @property (nonatomic, copy, setter = dk_setBackgroundColorPicker:) DKColorPicker dk_backgroundColorPicker; 17 | @property (nonatomic, copy, setter = dk_setTintColorPicker:) DKColorPicker dk_tintColorPicker; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /DKNightVersion/UIKit/UIView+Night.m: -------------------------------------------------------------------------------- 1 | // 2 | // UIView+Night.m 3 | // UIView+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "UIView+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface UIView () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation UIView (Night) 22 | 23 | 24 | - (DKColorPicker)dk_backgroundColorPicker { 25 | return objc_getAssociatedObject(self, @selector(dk_backgroundColorPicker)); 26 | } 27 | 28 | - (void)dk_setBackgroundColorPicker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_backgroundColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.backgroundColor = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@"setBackgroundColor:"]; 32 | } 33 | 34 | - (DKColorPicker)dk_tintColorPicker { 35 | return objc_getAssociatedObject(self, @selector(dk_tintColorPicker)); 36 | } 37 | 38 | - (void)dk_setTintColorPicker:(DKColorPicker)picker { 39 | objc_setAssociatedObject(self, @selector(dk_tintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 40 | self.tintColor = picker(self.dk_manager.themeVersion); 41 | [self.pickers setValue:[picker copy] forKey:@"setTintColor:"]; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /DKNightVersion/extobjc/EXTKeyPathCoding.h: -------------------------------------------------------------------------------- 1 | // 2 | // EXTKeyPathCoding.h 3 | // extobjc 4 | // 5 | // Created by Justin Spahr-Summers on 19.06.12. 6 | // Copyright (C) 2012 Justin Spahr-Summers. 7 | // Released under the MIT license. 8 | // 9 | 10 | #import 11 | #import "metamacros.h" 12 | 13 | /** 14 | * \@keypath allows compile-time verification of key paths. Given a real object 15 | * receiver and key path: 16 | * 17 | * @code 18 | 19 | NSString *UTF8StringPath = @keypath(str.lowercaseString.UTF8String); 20 | // => @"lowercaseString.UTF8String" 21 | 22 | NSString *versionPath = @keypath(NSObject, version); 23 | // => @"version" 24 | 25 | NSString *lowercaseStringPath = @keypath(NSString.new, lowercaseString); 26 | // => @"lowercaseString" 27 | 28 | * @endcode 29 | * 30 | * ... the macro returns an \c NSString containing all but the first path 31 | * component or argument (e.g., @"lowercaseString.UTF8String", @"version"). 32 | * 33 | * In addition to simply creating a key path, this macro ensures that the key 34 | * path is valid at compile-time (causing a syntax error if not), and supports 35 | * refactoring, such that changing the name of the property will also update any 36 | * uses of \@keypath. 37 | */ 38 | #define keypath(...) \ 39 | metamacro_if_eq(1, metamacro_argcount(__VA_ARGS__))(keypath1(__VA_ARGS__))(keypath2(__VA_ARGS__)) 40 | 41 | #define keypath1(PATH) \ 42 | (((void)(NO && ((void)PATH, NO)), strchr(# PATH, '.') + 1)) 43 | 44 | #define keypath2(OBJ, PATH) \ 45 | (((void)(NO && ((void)OBJ.PATH, NO)), # PATH)) 46 | 47 | /** 48 | * \@collectionKeypath allows compile-time verification of key paths across collections NSArray/NSSet etc. Given a real object 49 | * receiver, collection object receiver and related keypaths: 50 | * 51 | * @code 52 | 53 | NSString *employessFirstNamePath = @collectionKeypath(department.employees, Employee.new, firstName) 54 | // => @"employees.firstName" 55 | 56 | NSString *employessFirstNamePath = @collectionKeypath(Department.new, employees, Employee.new, firstName) 57 | // => @"employees.firstName" 58 | 59 | * @endcode 60 | * 61 | */ 62 | #define collectionKeypath(...) \ 63 | metamacro_if_eq(3, metamacro_argcount(__VA_ARGS__))(collectionKeypath3(__VA_ARGS__))(collectionKeypath4(__VA_ARGS__)) 64 | 65 | #define collectionKeypath3(PATH, COLLECTION_OBJECT, COLLECTION_PATH) ([[NSString stringWithFormat:@"%s.%s",keypath(PATH), keypath(COLLECTION_OBJECT, COLLECTION_PATH)] UTF8String]) 66 | 67 | #define collectionKeypath4(OBJ, PATH, COLLECTION_OBJECT, COLLECTION_PATH) ([[NSString stringWithFormat:@"%s.%s",keypath(OBJ, PATH), keypath(COLLECTION_OBJECT, COLLECTION_PATH)] UTF8String]) 68 | 69 | -------------------------------------------------------------------------------- /EXTKeyPathCoding.h: -------------------------------------------------------------------------------- 1 | ../../../DKNightVersion/DKNightVersion/extobjc/EXTKeyPathCoding.h -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 7261ADF91CB9FB2D007E283C /* PresentingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7261ADF21CB9FB2D007E283C /* PresentingViewController.m */; }; 11 | 7261ADFA1CB9FB2D007E283C /* RootViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7261ADF41CB9FB2D007E283C /* RootViewController.m */; }; 12 | 7261ADFB1CB9FB2D007E283C /* SuccViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 7261ADF61CB9FB2D007E283C /* SuccViewController.m */; }; 13 | 7261ADFC1CB9FB2D007E283C /* TableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 7261ADF81CB9FB2D007E283C /* TableViewCell.m */; }; 14 | 7292FC181D673B030054F827 /* DKNightVersion.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 7292FC171D673B030054F827 /* DKNightVersion.framework */; }; 15 | 729323FA1CB9FAF1009E544E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 729323F91CB9FAF1009E544E /* main.m */; }; 16 | 729323FD1CB9FAF1009E544E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 729323FC1CB9FAF1009E544E /* AppDelegate.m */; }; 17 | 729324001CB9FAF1009E544E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 729323FF1CB9FAF1009E544E /* ViewController.m */; }; 18 | 729324031CB9FAF1009E544E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 729324011CB9FAF1009E544E /* Main.storyboard */; }; 19 | 729324051CB9FAF1009E544E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 729324041CB9FAF1009E544E /* Assets.xcassets */; }; 20 | 729324081CB9FAF1009E544E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 729324061CB9FAF1009E544E /* LaunchScreen.storyboard */; }; 21 | 72E18B9F1CBA038E0004EBB2 /* DKColorTable.txt in Resources */ = {isa = PBXBuildFile; fileRef = 72E18B9E1CBA038E0004EBB2 /* DKColorTable.txt */; }; 22 | /* End PBXBuildFile section */ 23 | 24 | /* Begin PBXFileReference section */ 25 | 7261ADF11CB9FB2D007E283C /* PresentingViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PresentingViewController.h; sourceTree = ""; }; 26 | 7261ADF21CB9FB2D007E283C /* PresentingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PresentingViewController.m; sourceTree = ""; }; 27 | 7261ADF31CB9FB2D007E283C /* RootViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RootViewController.h; sourceTree = ""; }; 28 | 7261ADF41CB9FB2D007E283C /* RootViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RootViewController.m; sourceTree = ""; }; 29 | 7261ADF51CB9FB2D007E283C /* SuccViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SuccViewController.h; sourceTree = ""; }; 30 | 7261ADF61CB9FB2D007E283C /* SuccViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SuccViewController.m; sourceTree = ""; }; 31 | 7261ADF71CB9FB2D007E283C /* TableViewCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewCell.h; sourceTree = ""; }; 32 | 7261ADF81CB9FB2D007E283C /* TableViewCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewCell.m; sourceTree = ""; }; 33 | 7292FC171D673B030054F827 /* DKNightVersion.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = DKNightVersion.framework; path = "../Build/Products/Debug-iphonesimulator/DKNightVersion.framework"; sourceTree = ""; }; 34 | 729323F51CB9FAF1009E544E /* Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; 35 | 729323F91CB9FAF1009E544E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 36 | 729323FB1CB9FAF1009E544E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 37 | 729323FC1CB9FAF1009E544E /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 38 | 729323FE1CB9FAF1009E544E /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 39 | 729323FF1CB9FAF1009E544E /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 40 | 729324021CB9FAF1009E544E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 41 | 729324041CB9FAF1009E544E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 42 | 729324071CB9FAF1009E544E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 43 | 729324091CB9FAF1009E544E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 44 | 72E18B9E1CBA038E0004EBB2 /* DKColorTable.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = DKColorTable.txt; path = ../../DKNightVersion/ColorTable/DKColorTable.txt; sourceTree = ""; }; 45 | /* End PBXFileReference section */ 46 | 47 | /* Begin PBXFrameworksBuildPhase section */ 48 | 729323F21CB9FAF1009E544E /* Frameworks */ = { 49 | isa = PBXFrameworksBuildPhase; 50 | buildActionMask = 2147483647; 51 | files = ( 52 | 7292FC181D673B030054F827 /* DKNightVersion.framework in Frameworks */, 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | /* End PBXFrameworksBuildPhase section */ 57 | 58 | /* Begin PBXGroup section */ 59 | 729323EC1CB9FAF1009E544E = { 60 | isa = PBXGroup; 61 | children = ( 62 | 7292FC171D673B030054F827 /* DKNightVersion.framework */, 63 | 729323F71CB9FAF1009E544E /* Example */, 64 | 729323F61CB9FAF1009E544E /* Products */, 65 | ); 66 | sourceTree = ""; 67 | }; 68 | 729323F61CB9FAF1009E544E /* Products */ = { 69 | isa = PBXGroup; 70 | children = ( 71 | 729323F51CB9FAF1009E544E /* Example.app */, 72 | ); 73 | name = Products; 74 | sourceTree = ""; 75 | }; 76 | 729323F71CB9FAF1009E544E /* Example */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | 729323FB1CB9FAF1009E544E /* AppDelegate.h */, 80 | 729323FC1CB9FAF1009E544E /* AppDelegate.m */, 81 | 729323FE1CB9FAF1009E544E /* ViewController.h */, 82 | 729323FF1CB9FAF1009E544E /* ViewController.m */, 83 | 7261ADF11CB9FB2D007E283C /* PresentingViewController.h */, 84 | 7261ADF21CB9FB2D007E283C /* PresentingViewController.m */, 85 | 7261ADF31CB9FB2D007E283C /* RootViewController.h */, 86 | 7261ADF41CB9FB2D007E283C /* RootViewController.m */, 87 | 7261ADF51CB9FB2D007E283C /* SuccViewController.h */, 88 | 7261ADF61CB9FB2D007E283C /* SuccViewController.m */, 89 | 7261ADF71CB9FB2D007E283C /* TableViewCell.h */, 90 | 7261ADF81CB9FB2D007E283C /* TableViewCell.m */, 91 | 729324011CB9FAF1009E544E /* Main.storyboard */, 92 | 729324041CB9FAF1009E544E /* Assets.xcassets */, 93 | 729324061CB9FAF1009E544E /* LaunchScreen.storyboard */, 94 | 729324091CB9FAF1009E544E /* Info.plist */, 95 | 729323F81CB9FAF1009E544E /* Supporting Files */, 96 | ); 97 | path = Example; 98 | sourceTree = ""; 99 | }; 100 | 729323F81CB9FAF1009E544E /* Supporting Files */ = { 101 | isa = PBXGroup; 102 | children = ( 103 | 72E18B9E1CBA038E0004EBB2 /* DKColorTable.txt */, 104 | 729323F91CB9FAF1009E544E /* main.m */, 105 | ); 106 | name = "Supporting Files"; 107 | sourceTree = ""; 108 | }; 109 | /* End PBXGroup section */ 110 | 111 | /* Begin PBXNativeTarget section */ 112 | 729323F41CB9FAF1009E544E /* Example */ = { 113 | isa = PBXNativeTarget; 114 | buildConfigurationList = 7293240C1CB9FAF1009E544E /* Build configuration list for PBXNativeTarget "Example" */; 115 | buildPhases = ( 116 | 729323F11CB9FAF1009E544E /* Sources */, 117 | 729323F21CB9FAF1009E544E /* Frameworks */, 118 | 729323F31CB9FAF1009E544E /* Resources */, 119 | ); 120 | buildRules = ( 121 | ); 122 | dependencies = ( 123 | ); 124 | name = Example; 125 | productName = Example; 126 | productReference = 729323F51CB9FAF1009E544E /* Example.app */; 127 | productType = "com.apple.product-type.application"; 128 | }; 129 | /* End PBXNativeTarget section */ 130 | 131 | /* Begin PBXProject section */ 132 | 729323ED1CB9FAF1009E544E /* Project object */ = { 133 | isa = PBXProject; 134 | attributes = { 135 | LastUpgradeCheck = 0810; 136 | ORGANIZATIONNAME = Draveness; 137 | TargetAttributes = { 138 | 729323F41CB9FAF1009E544E = { 139 | CreatedOnToolsVersion = 7.3; 140 | }; 141 | }; 142 | }; 143 | buildConfigurationList = 729323F01CB9FAF1009E544E /* Build configuration list for PBXProject "Example" */; 144 | compatibilityVersion = "Xcode 3.2"; 145 | developmentRegion = English; 146 | hasScannedForEncodings = 0; 147 | knownRegions = ( 148 | en, 149 | Base, 150 | ); 151 | mainGroup = 729323EC1CB9FAF1009E544E; 152 | productRefGroup = 729323F61CB9FAF1009E544E /* Products */; 153 | projectDirPath = ""; 154 | projectRoot = ""; 155 | targets = ( 156 | 729323F41CB9FAF1009E544E /* Example */, 157 | ); 158 | }; 159 | /* End PBXProject section */ 160 | 161 | /* Begin PBXResourcesBuildPhase section */ 162 | 729323F31CB9FAF1009E544E /* Resources */ = { 163 | isa = PBXResourcesBuildPhase; 164 | buildActionMask = 2147483647; 165 | files = ( 166 | 729324081CB9FAF1009E544E /* LaunchScreen.storyboard in Resources */, 167 | 729324051CB9FAF1009E544E /* Assets.xcassets in Resources */, 168 | 72E18B9F1CBA038E0004EBB2 /* DKColorTable.txt in Resources */, 169 | 729324031CB9FAF1009E544E /* Main.storyboard in Resources */, 170 | ); 171 | runOnlyForDeploymentPostprocessing = 0; 172 | }; 173 | /* End PBXResourcesBuildPhase section */ 174 | 175 | /* Begin PBXSourcesBuildPhase section */ 176 | 729323F11CB9FAF1009E544E /* Sources */ = { 177 | isa = PBXSourcesBuildPhase; 178 | buildActionMask = 2147483647; 179 | files = ( 180 | 7261ADFC1CB9FB2D007E283C /* TableViewCell.m in Sources */, 181 | 729324001CB9FAF1009E544E /* ViewController.m in Sources */, 182 | 729323FD1CB9FAF1009E544E /* AppDelegate.m in Sources */, 183 | 729323FA1CB9FAF1009E544E /* main.m in Sources */, 184 | 7261ADF91CB9FB2D007E283C /* PresentingViewController.m in Sources */, 185 | 7261ADFB1CB9FB2D007E283C /* SuccViewController.m in Sources */, 186 | 7261ADFA1CB9FB2D007E283C /* RootViewController.m in Sources */, 187 | ); 188 | runOnlyForDeploymentPostprocessing = 0; 189 | }; 190 | /* End PBXSourcesBuildPhase section */ 191 | 192 | /* Begin PBXVariantGroup section */ 193 | 729324011CB9FAF1009E544E /* Main.storyboard */ = { 194 | isa = PBXVariantGroup; 195 | children = ( 196 | 729324021CB9FAF1009E544E /* Base */, 197 | ); 198 | name = Main.storyboard; 199 | sourceTree = ""; 200 | }; 201 | 729324061CB9FAF1009E544E /* LaunchScreen.storyboard */ = { 202 | isa = PBXVariantGroup; 203 | children = ( 204 | 729324071CB9FAF1009E544E /* Base */, 205 | ); 206 | name = LaunchScreen.storyboard; 207 | sourceTree = ""; 208 | }; 209 | /* End PBXVariantGroup section */ 210 | 211 | /* Begin XCBuildConfiguration section */ 212 | 7293240A1CB9FAF1009E544E /* Debug */ = { 213 | isa = XCBuildConfiguration; 214 | buildSettings = { 215 | ALWAYS_SEARCH_USER_PATHS = NO; 216 | CLANG_ANALYZER_NONNULL = YES; 217 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 218 | CLANG_CXX_LIBRARY = "libc++"; 219 | CLANG_ENABLE_MODULES = YES; 220 | CLANG_ENABLE_OBJC_ARC = YES; 221 | CLANG_WARN_BOOL_CONVERSION = YES; 222 | CLANG_WARN_CONSTANT_CONVERSION = YES; 223 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 224 | CLANG_WARN_EMPTY_BODY = YES; 225 | CLANG_WARN_ENUM_CONVERSION = YES; 226 | CLANG_WARN_INFINITE_RECURSION = YES; 227 | CLANG_WARN_INT_CONVERSION = YES; 228 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 229 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 230 | CLANG_WARN_UNREACHABLE_CODE = YES; 231 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 232 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 233 | COPY_PHASE_STRIP = NO; 234 | DEBUG_INFORMATION_FORMAT = dwarf; 235 | ENABLE_STRICT_OBJC_MSGSEND = YES; 236 | ENABLE_TESTABILITY = YES; 237 | GCC_C_LANGUAGE_STANDARD = gnu99; 238 | GCC_DYNAMIC_NO_PIC = NO; 239 | GCC_NO_COMMON_BLOCKS = YES; 240 | GCC_OPTIMIZATION_LEVEL = 0; 241 | GCC_PREPROCESSOR_DEFINITIONS = ( 242 | "DEBUG=1", 243 | "$(inherited)", 244 | ); 245 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 246 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 247 | GCC_WARN_UNDECLARED_SELECTOR = YES; 248 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 249 | GCC_WARN_UNUSED_FUNCTION = YES; 250 | GCC_WARN_UNUSED_VARIABLE = YES; 251 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 252 | MTL_ENABLE_DEBUG_INFO = YES; 253 | ONLY_ACTIVE_ARCH = YES; 254 | SDKROOT = iphoneos; 255 | }; 256 | name = Debug; 257 | }; 258 | 7293240B1CB9FAF1009E544E /* Release */ = { 259 | isa = XCBuildConfiguration; 260 | buildSettings = { 261 | ALWAYS_SEARCH_USER_PATHS = NO; 262 | CLANG_ANALYZER_NONNULL = YES; 263 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 264 | CLANG_CXX_LIBRARY = "libc++"; 265 | CLANG_ENABLE_MODULES = YES; 266 | CLANG_ENABLE_OBJC_ARC = YES; 267 | CLANG_WARN_BOOL_CONVERSION = YES; 268 | CLANG_WARN_CONSTANT_CONVERSION = YES; 269 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 270 | CLANG_WARN_EMPTY_BODY = YES; 271 | CLANG_WARN_ENUM_CONVERSION = YES; 272 | CLANG_WARN_INFINITE_RECURSION = YES; 273 | CLANG_WARN_INT_CONVERSION = YES; 274 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 275 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 276 | CLANG_WARN_UNREACHABLE_CODE = YES; 277 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 278 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 279 | COPY_PHASE_STRIP = NO; 280 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 281 | ENABLE_NS_ASSERTIONS = NO; 282 | ENABLE_STRICT_OBJC_MSGSEND = YES; 283 | GCC_C_LANGUAGE_STANDARD = gnu99; 284 | GCC_NO_COMMON_BLOCKS = YES; 285 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 286 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 287 | GCC_WARN_UNDECLARED_SELECTOR = YES; 288 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 289 | GCC_WARN_UNUSED_FUNCTION = YES; 290 | GCC_WARN_UNUSED_VARIABLE = YES; 291 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 292 | MTL_ENABLE_DEBUG_INFO = NO; 293 | SDKROOT = iphoneos; 294 | VALIDATE_PRODUCT = YES; 295 | }; 296 | name = Release; 297 | }; 298 | 7293240D1CB9FAF1009E544E /* Debug */ = { 299 | isa = XCBuildConfiguration; 300 | buildSettings = { 301 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 302 | CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO; 303 | INFOPLIST_FILE = Example/Info.plist; 304 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 305 | PRODUCT_BUNDLE_IDENTIFIER = com.draveness.Example; 306 | PRODUCT_NAME = "$(TARGET_NAME)"; 307 | }; 308 | name = Debug; 309 | }; 310 | 7293240E1CB9FAF1009E544E /* Release */ = { 311 | isa = XCBuildConfiguration; 312 | buildSettings = { 313 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 314 | CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = NO; 315 | INFOPLIST_FILE = Example/Info.plist; 316 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 317 | PRODUCT_BUNDLE_IDENTIFIER = com.draveness.Example; 318 | PRODUCT_NAME = "$(TARGET_NAME)"; 319 | }; 320 | name = Release; 321 | }; 322 | /* End XCBuildConfiguration section */ 323 | 324 | /* Begin XCConfigurationList section */ 325 | 729323F01CB9FAF1009E544E /* Build configuration list for PBXProject "Example" */ = { 326 | isa = XCConfigurationList; 327 | buildConfigurations = ( 328 | 7293240A1CB9FAF1009E544E /* Debug */, 329 | 7293240B1CB9FAF1009E544E /* Release */, 330 | ); 331 | defaultConfigurationIsVisible = 0; 332 | defaultConfigurationName = Release; 333 | }; 334 | 7293240C1CB9FAF1009E544E /* Build configuration list for PBXNativeTarget "Example" */ = { 335 | isa = XCConfigurationList; 336 | buildConfigurations = ( 337 | 7293240D1CB9FAF1009E544E /* Debug */, 338 | 7293240E1CB9FAF1009E544E /* Release */, 339 | ); 340 | defaultConfigurationIsVisible = 0; 341 | defaultConfigurationName = Release; 342 | }; 343 | /* End XCConfigurationList section */ 344 | }; 345 | rootObject = 729323ED1CB9FAF1009E544E /* Project object */; 346 | } 347 | -------------------------------------------------------------------------------- /Example/Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Example/Example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // Example 4 | // 5 | // Created by Draveness on 16/4/10. 6 | // Copyright © 2016年 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /Example/Example/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // Example 4 | // 5 | // Created by Draveness on 16/4/10. 6 | // Copyright © 2016年 Draveness. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "RootViewController.h" 11 | #import "SuccViewController.h" 12 | 13 | @interface AppDelegate () 14 | 15 | @end 16 | 17 | @implementation AppDelegate 18 | 19 | 20 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 21 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 22 | // Override point for customization after application launch. 23 | self.window.backgroundColor = [UIColor whiteColor]; 24 | [self.window makeKeyAndVisible]; 25 | UINavigationController *navigation = [[UINavigationController alloc] initWithRootViewController:[[RootViewController alloc] init]]; 26 | self.window.rootViewController = navigation; 27 | UISearchBar *searchBar = [[UISearchBar alloc] init]; 28 | return YES; 29 | } 30 | 31 | - (void)applicationWillResignActive:(UIApplication *)application { 32 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 33 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 34 | } 35 | 36 | - (void)applicationDidEnterBackground:(UIApplication *)application { 37 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 38 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 39 | } 40 | 41 | - (void)applicationWillEnterForeground:(UIApplication *)application { 42 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 43 | } 44 | 45 | - (void)applicationDidBecomeActive:(UIApplication *)application { 46 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 47 | } 48 | 49 | - (void)applicationWillTerminate:(UIApplication *)application { 50 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 51 | } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/night.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "night.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/night.imageset/night.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/draveness/DKNightVersion/a59ad0b5a9b4c15ba18f3bae30c2f61e542f2970/Example/Example/Assets.xcassets/night.imageset/night.png -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/night1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "night1.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/night1.imageset/night1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/draveness/DKNightVersion/a59ad0b5a9b4c15ba18f3bae30c2f61e542f2970/Example/Example/Assets.xcassets/night1.imageset/night1.png -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/normal.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "normal.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/normal.imageset/normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/draveness/DKNightVersion/a59ad0b5a9b4c15ba18f3bae30c2f61e542f2970/Example/Example/Assets.xcassets/normal.imageset/normal.png -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/normal1.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "normal1.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "scale" : "3x" 15 | } 16 | ], 17 | "info" : { 18 | "version" : 1, 19 | "author" : "xcode" 20 | } 21 | } -------------------------------------------------------------------------------- /Example/Example/Assets.xcassets/normal1.imageset/normal1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/draveness/DKNightVersion/a59ad0b5a9b4c15ba18f3bae30c2f61e542f2970/Example/Example/Assets.xcassets/normal1.imageset/normal1.png -------------------------------------------------------------------------------- /Example/Example/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Example/Example/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Example/Example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UIViewControllerBasedStatusBarAppearance 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Example/Example/PresentingViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // PresentingViewController.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/5/10. 6 | // Copyright (c) 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface PresentingViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Example/Example/PresentingViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // PresentingViewController.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 15/5/10. 6 | // Copyright (c) 2015年 DeltaX. All rights reserved. 7 | // 8 | 9 | #import "PresentingViewController.h" 10 | #import 11 | 12 | @interface PresentingViewController () 13 | 14 | @end 15 | 16 | @implementation PresentingViewController 17 | 18 | - (void)viewDidLoad { 19 | [super viewDidLoad]; 20 | UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 21 | [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside]; 22 | [button setFrame:CGRectMake(self.view.frame.size.height / 2.0, 0, self.view.frame.size.width, self.view.frame.size.height / 2.0)]; 23 | button.center = CGPointMake(self.view.center.x, self.view.center.y * 1.5); 24 | [button setTitle:@"Back" forState:UIControlStateNormal]; 25 | 26 | UIButton *switchButton = [UIButton buttonWithType:UIButtonTypeCustom]; 27 | [switchButton addTarget:self action:@selector(switchColor) forControlEvents:UIControlEventTouchUpInside]; 28 | [switchButton setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height / 2.0)]; 29 | switchButton.center = CGPointMake(self.view.center.x, self.view.center.y * 0.5); 30 | [switchButton setTitle:@"SwitchColor" forState:UIControlStateNormal]; 31 | 32 | [self.view addSubview:button]; 33 | [self.view addSubview:switchButton]; 34 | 35 | self.view.dk_backgroundColorPicker = DKColorPickerWithKey(BG); 36 | [button dk_setTitleColorPicker:DKColorPickerWithKey(TINT) forState:UIControlStateNormal]; 37 | [switchButton dk_setTitleColorPicker:DKColorPickerWithKey(TINT) forState:UIControlStateNormal]; 38 | 39 | } 40 | 41 | - (void)back { 42 | [self dismissViewControllerAnimated:YES completion:nil]; 43 | } 44 | 45 | - (void)switchColor { 46 | if ([self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) { 47 | [self.dk_manager dawnComing]; 48 | } else { 49 | [self.dk_manager nightFalling]; 50 | } 51 | } 52 | 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Example/Example/RootViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // RootViewController.h 3 | // DKNightVerision 4 | // 5 | // Created by Draveness on 4/14/15. 6 | // Copyright (c) 2015 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface RootViewController : UITableViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Example/Example/RootViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // RootViewController.m 3 | // DKNightVerision 4 | // 5 | // Created by Draveness on 4/14/15. 6 | // Copyright (c) 2015 Draveness. All rights reserved. 7 | // 8 | 9 | #import "RootViewController.h" 10 | #import "SuccViewController.h" 11 | #import "PresentingViewController.h" 12 | #import 13 | #import "TableViewCell.h" 14 | 15 | @pickerify(TableViewCell, cellTintColor) 16 | 17 | @interface RootViewController () 18 | 19 | @end 20 | 21 | @implementation RootViewController 22 | 23 | - (void)viewDidLoad { 24 | [super viewDidLoad]; 25 | [self.tableView registerClass:[TableViewCell class] forCellReuseIdentifier:@"Cell"]; 26 | self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; 27 | UILabel *navigationLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 375, 44)]; 28 | navigationLabel.text = @"DKNightVersion"; 29 | navigationLabel.textAlignment = NSTextAlignmentCenter; 30 | self.navigationItem.titleView = navigationLabel; 31 | 32 | UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"Present" style:UIBarButtonItemStylePlain target:self action:@selector(present)]; 33 | self.navigationItem.leftBarButtonItem = item; 34 | 35 | UIBarButtonItem *normalItem = [[UIBarButtonItem alloc] initWithTitle:@"Normal" style:UIBarButtonItemStylePlain target:self action:@selector(normal)]; 36 | normalItem.dk_tintColorPicker = DKColorPickerWithKey(TINT); 37 | UIBarButtonItem *nightItem = [[UIBarButtonItem alloc] initWithTitle:@"Night" style:UIBarButtonItemStylePlain target:self action:@selector(night)]; 38 | nightItem.dk_tintColorPicker = DKColorPickerWithKey(TINT); 39 | UIBarButtonItem *redItem = [[UIBarButtonItem alloc] initWithTitle:@"Red" style:UIBarButtonItemStylePlain target:self action:@selector(red)]; 40 | redItem.dk_tintColorPicker = DKColorPickerWithKey(TINT); 41 | 42 | self.navigationItem.rightBarButtonItems = @[normalItem, nightItem, redItem]; 43 | 44 | // self.tableView.dk_backgroundColorPicker = DKColorPickerWithKey(BG); 45 | self.tableView.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff, 0x343434, 0xfafafa); 46 | self.tableView.dk_separatorColorPicker = DKColorPickerWithKey(SEP); 47 | navigationLabel.dk_textColorPicker = DKColorPickerWithKey(TEXT); 48 | self.navigationController.navigationBar.dk_barTintColorPicker = DKColorPickerWithKey(BAR); 49 | self.navigationItem.leftBarButtonItem.dk_tintColorPicker = DKColorPickerWithKey(TINT); 50 | } 51 | 52 | - (void)night { 53 | self.dk_manager.themeVersion = DKThemeVersionNight; 54 | } 55 | 56 | - (void)normal { 57 | self.dk_manager.themeVersion = DKThemeVersionNormal; 58 | } 59 | 60 | - (void)red { 61 | self.dk_manager.themeVersion = @"RED"; 62 | } 63 | 64 | - (void)change { 65 | 66 | if ([self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) { 67 | [self.dk_manager dawnComing]; 68 | } else { 69 | [self.dk_manager nightFalling]; 70 | } 71 | } 72 | 73 | - (void)push { 74 | [self.navigationController pushViewController:[[SuccViewController alloc] init] animated:YES]; 75 | } 76 | 77 | - (void)present { 78 | [self presentViewController:[[PresentingViewController alloc] init] animated:YES completion:nil]; 79 | } 80 | 81 | #pragma mark - UITableView Delegate & DataSource 82 | 83 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 84 | return 10; 85 | } 86 | 87 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 88 | return 1; 89 | } 90 | 91 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 92 | TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 93 | cell.dk_cellTintColorPicker = DKColorPickerWithRGB(0xffffff, 0x343434, 0xfafafa); 94 | 95 | return cell; 96 | } 97 | 98 | - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 99 | return 100; 100 | } 101 | 102 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 103 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 104 | [self push]; 105 | } 106 | 107 | @end 108 | -------------------------------------------------------------------------------- /Example/Example/SuccViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // SuccViewController.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 4/28/15. 6 | // Copyright (c) 2015 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface SuccViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /Example/Example/SuccViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // SuccViewController.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 4/28/15. 6 | // Copyright (c) 2015 Draveness. All rights reserved. 7 | // 8 | 9 | #import "SuccViewController.h" 10 | #import 11 | 12 | @interface SuccViewController () 13 | 14 | @end 15 | 16 | @implementation SuccViewController 17 | 18 | - (void)viewWillAppear:(BOOL)animated { 19 | [super viewWillAppear:animated]; 20 | } 21 | 22 | - (void)viewDidLoad { 23 | [super viewDidLoad]; 24 | 25 | self.view.dk_backgroundColorPicker = DKColorPickerWithKey(BG); 26 | self.navigationController.navigationBar.dk_tintColorPicker = DKColorPickerWithKey(TINT); 27 | 28 | UITextField *textField = [[UITextField alloc] init]; 29 | textField.frame = self.view.frame; 30 | textField.dk_textColorPicker = DKColorPickerWithKey(TEXT); 31 | [self.view addSubview:textField]; 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Example/Example/TableViewCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewCell.h 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 5/1/15. 6 | // Copyright (c) 2015 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface TableViewCell : UITableViewCell 12 | 13 | @property (strong, nonatomic) UILabel *label; 14 | @property (strong, nonatomic) UIButton *button; 15 | 16 | @property (strong, nonatomic) UIColor *cellTintColor; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Example/Example/TableViewCell.m: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewCell.m 3 | // DKNightVersion 4 | // 5 | // Created by Draveness on 5/1/15. 6 | // Copyright (c) 2015 Draveness. All rights reserved. 7 | // 8 | 9 | #import "TableViewCell.h" 10 | #import 11 | 12 | @interface TableViewCell () 13 | 14 | @end 15 | 16 | @implementation TableViewCell 17 | 18 | - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { 19 | if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) { 20 | self.label = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 270, 80)]; 21 | self.label.numberOfLines = 0; 22 | self.label.text = @"DKNightVersion is a light weight framework adding night mode to your iOS app."; 23 | self.label.textColor = [UIColor darkGrayColor]; 24 | self.label.lineBreakMode = NSLineBreakByCharWrapping; 25 | [self.contentView addSubview:self.label]; 26 | 27 | CGRect rect = CGRectMake(250, 10, 120, 80); 28 | self.button = [[UIButton alloc] initWithFrame:rect]; 29 | self.button.titleLabel.font = [UIFont systemFontOfSize:20]; 30 | [self.button setTitleColor:[UIColor colorWithRed:0.478 green:0.651 blue:0.988 alpha:1.0] forState:UIControlStateNormal]; 31 | 32 | self.selectionStyle = UITableViewCellSelectionStyleNone; 33 | [self.contentView addSubview:self.button]; 34 | 35 | // self.contentView.dk_backgroundColorPicker = DKColorPickerWithKey(BG); 36 | 37 | UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(300, 25, 50, 50)]; 38 | 39 | imageView.dk_imagePicker = DKImagePickerWithNames(@"normal1", @"normal1", @"normal1"); 40 | imageView.dk_alphaPicker = DKAlphaPickerWithAlphas(1.f, 0.5f, 0.1f); 41 | [self.contentView addSubview:imageView]; 42 | } 43 | return self; 44 | } 45 | 46 | - (void)setCellTintColor:(UIColor *)cellTintColor { 47 | _cellTintColor = cellTintColor; 48 | self.contentView.backgroundColor = _cellTintColor; 49 | } 50 | 51 | - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { 52 | [super setHighlighted:highlighted animated:animated]; 53 | if (highlighted) { 54 | self.contentView.dk_backgroundColorPicker = DKColorPickerWithKey(HIGHLIGHTED); 55 | } else { 56 | self.contentView.dk_backgroundColorPicker = DKColorPickerWithKey(BG); 57 | } 58 | } 59 | 60 | @end 61 | -------------------------------------------------------------------------------- /Example/Example/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // Example 4 | // 5 | // Created by Draveness on 16/4/10. 6 | // Copyright © 2016年 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /Example/Example/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // Example 4 | // 5 | // Created by Draveness on 16/4/10. 6 | // Copyright © 2016年 Draveness. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | 11 | @interface ViewController () 12 | 13 | @end 14 | 15 | @implementation ViewController 16 | 17 | - (void)viewDidLoad { 18 | [super viewDidLoad]; 19 | // Do any additional setup after loading the view, typically from a nib. 20 | } 21 | 22 | - (void)didReceiveMemoryWarning { 23 | [super didReceiveMemoryWarning]; 24 | // Dispose of any resources that can be recreated. 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Example/Example/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Example 4 | // 5 | // Created by Draveness on 16/4/10. 6 | // Copyright © 2016年 Draveness. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gem 'colorize' 4 | gem 'rake' 5 | gem 'xcodeproj' 6 | gem 'cocoapods', '~> 1.2.0' 7 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | CFPropertyList (2.3.5) 5 | activesupport (4.2.8) 6 | i18n (~> 0.7) 7 | minitest (~> 5.1) 8 | thread_safe (~> 0.3, >= 0.3.4) 9 | tzinfo (~> 1.1) 10 | claide (1.0.1) 11 | cocoapods (1.2.0) 12 | activesupport (>= 4.0.2, < 5) 13 | claide (>= 1.0.1, < 2.0) 14 | cocoapods-core (= 1.2.0) 15 | cocoapods-deintegrate (>= 1.0.1, < 2.0) 16 | cocoapods-downloader (>= 1.1.3, < 2.0) 17 | cocoapods-plugins (>= 1.0.0, < 2.0) 18 | cocoapods-search (>= 1.0.0, < 2.0) 19 | cocoapods-stats (>= 1.0.0, < 2.0) 20 | cocoapods-trunk (>= 1.1.2, < 2.0) 21 | cocoapods-try (>= 1.1.0, < 2.0) 22 | colored (~> 1.2) 23 | escape (~> 0.0.4) 24 | fourflusher (~> 2.0.1) 25 | gh_inspector (~> 1.0) 26 | molinillo (~> 0.5.5) 27 | nap (~> 1.0) 28 | ruby-macho (~> 0.2.5) 29 | xcodeproj (>= 1.4.1, < 2.0) 30 | cocoapods-core (1.2.0) 31 | activesupport (>= 4.0.2, < 5) 32 | fuzzy_match (~> 2.0.4) 33 | nap (~> 1.0) 34 | cocoapods-deintegrate (1.0.1) 35 | cocoapods-downloader (1.1.3) 36 | cocoapods-plugins (1.0.0) 37 | nap 38 | cocoapods-search (1.0.0) 39 | cocoapods-stats (1.0.0) 40 | cocoapods-trunk (1.1.2) 41 | nap (>= 0.8, < 2.0) 42 | netrc (= 0.7.8) 43 | cocoapods-try (1.1.0) 44 | colored (1.2) 45 | colored2 (3.1.2) 46 | colorize (0.8.1) 47 | escape (0.0.4) 48 | fourflusher (2.0.1) 49 | fuzzy_match (2.0.4) 50 | gh_inspector (1.0.3) 51 | i18n (0.8.1) 52 | minitest (5.10.1) 53 | molinillo (0.5.7) 54 | nanaimo (0.2.3) 55 | nap (1.1.0) 56 | netrc (0.7.8) 57 | rake (12.0.0) 58 | ruby-macho (0.2.6) 59 | thread_safe (0.3.6) 60 | tzinfo (1.2.3) 61 | thread_safe (~> 0.1) 62 | xcodeproj (1.4.3) 63 | CFPropertyList (~> 2.3.3) 64 | activesupport (>= 3) 65 | claide (>= 1.0.1, < 2.0) 66 | colored2 (~> 3.1) 67 | nanaimo (~> 0.2.3) 68 | 69 | PLATFORMS 70 | ruby 71 | 72 | DEPENDENCIES 73 | cocoapods (~> 1.2.0) 74 | colorize 75 | rake 76 | xcodeproj 77 | 78 | BUNDLED WITH 79 | 1.14.6 80 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Draveness 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | ![](./images/Banner.png) 3 | 4 |

5 | 6 | 7 | 8 | 9 | 10 | 11 |

12 | 13 | - [x] Easily integrate and high performance 14 | - [x] Providing UIKit and CoreAnimation category 15 | - [x] Read colour customisation from file 16 | - [x] Support different themes 17 | - [x] Generate picker for other libs with one line macro 18 | 19 | 20 | # Demo 21 | 22 |

23 | 24 |

25 | 26 | ---- 27 | 28 | + [Installation with CocoaPods](#Installation-with-CocoaPods) 29 | + [Podfile](#podfile) 30 | + [Import](#import) 31 | + [Usage](#usage) 32 | + [Advanced Usage](#advanced-usage) 33 | + [DKNightVersionManger](#dknightversionmanager) 34 | + [Change Theme](#change-theme) 35 | + [Post Notification](#post-notification) 36 | + [DKColorPicker](#dkColorpicker) 37 | + [DKColorTable](#dkcolortable) 38 | + [pickerify](#pickerify) 39 | + [Create temporary DKColorPicker](#create-temporary-dkcolorpicker) 40 | + [DKImagePicker](#dkimagepicker) 41 | 42 | > If you want to implement night mode in Swift project without import Objective-C code. [NightNight](https://github.com/Draveness/NightNight) 43 | is the Swift version which does the same work. 44 | 45 | # How To Get Started 46 | 47 | DKNightVersion supports multiple methods for installing the library in a project. 48 | 49 | ## Installation with CocoaPods 50 | 51 | [CocoaPods](https://cocoapods.org/) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like DKNightVersion in your projects. See the [Get Started section](https://cocoapods.org/#get_started) for more details. 52 | 53 | ### Podfile 54 | 55 | To integrate DKNightVersion into your Xcode project using CocoaPods, specify it in your `Podfile`: 56 | 57 | ```shell 58 | pod "DKNightVersion" 59 | ``` 60 | 61 | Then, run the following command: 62 | 63 | ```shell 64 | $ pod install 65 | ``` 66 | 67 | 68 | ### Import 69 | 70 | Import DKNightVersion header file 71 | 72 | ```objectivec 73 | #import 74 | ``` 75 | 76 | ## Usage 77 | 78 | Checkout `DKColorTable.txt` file in your project, which locates in `Pods/DKNightVersion/Resources/DKNightVersion.txt`. 79 | ``` 80 | NORMAL NIGHT 81 | #ffffff #343434 BG 82 | #aaaaaa #313131 SEP 83 | ``` 84 | 85 | > You can also create another colour table file, and specify it with [DKColorTable](#dkcolortable). 86 | 87 | A, set color picker like this with `DKColorPickerWithKey`, which generates a DKColorPicker block 88 | 89 | ```objectivec 90 | self.view.dk_backgroundColorPicker = DKColorPickerWithKey(BG); 91 | ``` 92 | 93 | After the current theme version change to `DKThemeVersionNight`, the view background colour would switch to `#343434`. 94 | 95 | ```objectivec 96 | [DKNightVersionManager nightFalling]; 97 | ``` 98 | 99 | Alternatively, you could change the theme version by manager's property `themeVersion` which is a string 100 | 101 | ```objectivec 102 | DKNightVersionManager *manager = [DKNightVersionManager sharedInstance]; 103 | manager.themeVersion = DKThemeVersionNormal; 104 | ``` 105 | 106 | ## Advanced Usage 107 | 108 | There are two approaches you can use to integrate night mode to your iOS App. 109 | 110 | ### DKNightVersionManager 111 | 112 | The latest version for DKNightVersion add a readonly `dk_manager` property for `NSObject` returns the `DKNightVersionManager` singleton. 113 | 114 | #### Change Theme 115 | 116 | You can call `nightFalling` or `dawnComing` to switch the current theme version to `DKThemeVersionNight` or `DKThemeVersionNormal`. 117 | 118 | ```objectivec 119 | [self.dk_manager dawnComing]; 120 | [self.dk_manager nightFalling]; 121 | ``` 122 | 123 | Modify `themeVersion` property to switch the theme version directly. 124 | 125 | ```objectivec 126 | self.dk_manager.themeVersion = DKThemeVersionNormal; 127 | self.dk_manager.themeVersion = DKThemeVersionNight; 128 | // if there is a RED column in DKColorTable.txt (default) or in 129 | // other `file` if you customize `file` property for `DKColorTable` 130 | self.dk_manager.themeVersion = @"RED"; 131 | ``` 132 | 133 | #### Post Notification 134 | 135 | Every time the current theme version changes, `DKNightVersionManager` would post a `DKNightVersionThemeChangingNotification`. If you want to do some customisation, you can observe this notification and react with proper actions. 136 | 137 | ### DKColorPicker 138 | 139 | `DKColorPicker` is the core of DKNightVersion. And this lib adds dk_colorPicker to every UIKit and Core Animation components. Ex: 140 | 141 | ```objectivec 142 | @property (nonatomic, copy, setter = dk_setBackgroundColorPicker:) DKColorPicker dk_backgroundColorPicker; 143 | @property (nonatomic, copy, setter = dk_setTintColorPicker:) DKColorPicker dk_tintColorPicker; 144 | ``` 145 | 146 | DKColorPicker is defined in `DKColor.h` file receives a `DKThemeVersion` as the parameter and returns a `UIColor`. 147 | 148 | ```objectivec 149 | typedef UIColor *(^DKColorPicker)(DKThemeVersion *themeVersion); 150 | ``` 151 | 152 | + Use `DKColorPickerWithKey(key)` to obtain `DKColorPicker` from `DKColorTable` 153 | 154 | ```objectivec 155 | view.dk_backgroundColorPicker = DKColorPickerWithKey(BG); 156 | ``` 157 | 158 | + Use `DKColorPickerWithRGB` to generate a `DKColorPicker` 159 | 160 | ```objectivec 161 | view.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff, 0x343434); 162 | ``` 163 | 164 | ### DKColorTable 165 | 166 | `DKColorTable` is a new feature in DKNightVersion which providing us with an elegant way to manage colour setting in a project. Use as follows: 167 | 168 | There is a file called `DKColorTable.txt` 169 | 170 | ``` 171 | NORMAL NIGHT 172 | #ffffff #343434 BG 173 | #aaaaaa #313131 SEP 174 | ``` 175 | 176 | The first line of this file indicated different themes. **NORMAL is required column**, and others are optional. So if you don't need to integrate different themes in your app, leave the first column in this file, like this: 177 | 178 | ``` 179 | NORMAL 180 | #ffffff BG 181 | #aaaaaa SEP 182 | ``` 183 | 184 | `NORMAL` and `NIGHT` are two different themes, `NORMAL` is the default and for normal mode. `NIGHT` is optional and for night mode. 185 | 186 | You can add multiple columns in this `DKColorTable.txt` file as many as you want. 187 | 188 | ``` 189 | NORMAL NIGHT RED 190 | #ffffff #343434 #ff0000 BG 191 | #aaaaaa #313131 #ff0000 SEP 192 | ``` 193 | 194 | The last column is the key for a colour entry, DKNightVersion uses the current `themeVersion` (ex: `NORMAL` `NIGHT` and `RED`) and key (ex: `BG`, `SEP`) to find the corresponding colour in DKColorTable. 195 | 196 | `DKColorTable` has a property `file`, it will loads the color setting in this `file` when `+ [DKColorTable sharedColorTable` is called. Default value of `file` is `DKColorTable.txt`. 197 | 198 | ```objectivec 199 | @property (nonatomic, strong) NSString *file; 200 | ``` 201 | 202 | You can also add another file into your project and fill your colour setting in that file. 203 | 204 | ``` 205 | // color.txt 206 | NORMAL NIGHT 207 | #ffffff #343434 BG 208 | ``` 209 | 210 | Also, do not forget to change the `file` property of the colour table. 211 | 212 | ```objectivec 213 | [DKColorTable sharedColorTable].file = @"color.txt" 214 | ``` 215 | 216 | The code above would reload colour setting from `color.txt` file. 217 | 218 | ### Create temporary DKColorPicker 219 | 220 | If you'd want to create some temporary DKColorPicker, you can use these methods. 221 | 222 | ```objectivec 223 | view.dk_backgroundColorPicker = DKColorPickerWithRGB(0xffffff, 0x343434); 224 | ``` 225 | 226 | `DKColorPickerWithRGB` will return a DKColorPicker which set background color to `#ffffff` when current theme version is `DKThemeVersionNormal` and `#343434` when it is `DKThemeVersionNight`. 227 | 228 | There are also some similar functions like `DKColorPickerWithColors` 229 | 230 | ```objectivec 231 | DKColorPicker DKColorPickerWithRGB(NSUInteger normal, ...); 232 | DKColorPicker DKColorPickerWithColors(UIColor *normalColor, ...); 233 | ``` 234 | 235 | `DKColor` also provides a cluster of convenient `API` which returns `DKColorPicker` block, these blocks **return the same colour in different themes**. 236 | 237 | ```objectivec 238 | + (DKColorPicker)colorPickerWithUIColor:(UIColor *)color; 239 | 240 | + (DKColorPicker)colorPickerWithWhite:(CGFloat)white alpha:(CGFloat)alpha; 241 | + (DKColorPicker)colorPickerWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha; 242 | + (DKColorPicker)colorPickerWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha; 243 | + (DKColorPicker)colorPickerWithCGColor:(CGColorRef)cgColor; 244 | + (DKColorPicker)colorPickerWithPatternImage:(UIImage *)image; 245 | #if __has_include() 246 | + (DKColorPicker)colorPickerWithCIColor:(CIColor *)ciColor NS_AVAILABLE_IOS(5_0); 247 | #endif 248 | 249 | + (DKColorPicker)blackColor; 250 | + (DKColorPicker)darkGrayColor; 251 | + (DKColorPicker)lightGrayColor; 252 | + (DKColorPicker)whiteColor; 253 | + (DKColorPicker)grayColor; 254 | + (DKColorPicker)redColor; 255 | + (DKColorPicker)greenColor; 256 | + (DKColorPicker)blueColor; 257 | + (DKColorPicker)cyanColor; 258 | + (DKColorPicker)yellowColor; 259 | + (DKColorPicker)magentaColor; 260 | + (DKColorPicker)orangeColor; 261 | + (DKColorPicker)purpleColor; 262 | + (DKColorPicker)brownColor; 263 | + (DKColorPicker)clearColor; 264 | ``` 265 | 266 | ### pickerify 267 | 268 | DKNightVersion provides a powerful feature which can generate dk_xxxColorPicker with a macro called `pickerify`. 269 | 270 | ```objectivec 271 | @pickerify(TableViewCell, cellTintColor) 272 | ``` 273 | 274 | It automatically generates `dk_cellTintColorPicker` for you. 275 | 276 | 277 | ### DKImagePicker 278 | 279 | Use `DKImagePicker` to change images when `manager.themeVersion` changes. 280 | 281 | ```objectivec 282 | imageView.dk_imagePicker = DKImagePickerWithNames(@"normal", @"night"); 283 | ``` 284 | 285 | The first argument passed into the function is used for `NORMAL` theme, and the second is used for `NIGHT` theme, the themes order is determined by the configuration in 286 | DKColorTable.txt file which is NORMAL and NIGHT. 287 | 288 | If your file like this: 289 | 290 | ``` 291 | NORMAL NIGHT RED 292 | #ffffff #343434 #fafafa BG 293 | #aaaaaa #313131 #aaaaaa SEP 294 | #0000ff #ffffff #fa0000 TINT 295 | #000000 #ffffff #000000 TEXT 296 | #ffffff #444444 #ffffff BAR 297 | ``` 298 | 299 | Set your image picker in this order: 300 | 301 | ```objectivec 302 | imageView.dk_imagePicker = DKImagePickerWithNames(@"normal", @"night", @"red"); 303 | ``` 304 | 305 | The order of images or names is the same in DKColorTable.txt file. 306 | 307 | ```objectivec 308 | DKImagePicker DKImagePickerWithImages(UIImage *normalImage, ...); 309 | DKImagePicker DKImagePickerWithNames(NSString *normalName, ...); 310 | ``` 311 | 312 | # Contribute 313 | 314 | Feel free to open an issue or pull request, if you need help or there is a bug. 315 | 316 | # Contact 317 | 318 | - Powered by [Draveness](http://github.com/draveness) 319 | - Personal website [Draveness](http://draveness.me) 320 | 321 | # Todo 322 | 323 | - Documentation 324 | 325 | # License 326 | 327 | DKNightVersion is available under the MIT license. See the LICENSE file for more info. 328 | 329 | The MIT License (MIT) 330 | 331 | Copyright (c) 2015 Draveness 332 | 333 | Permission is hereby granted, free of charge, to any person obtaining a copy 334 | of this software and associated documentation files (the "Software"), to deal 335 | in the Software without restriction, including without limitation the rights 336 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 337 | copies of the Software, and to permit persons to whom the Software is 338 | furnished to do so, subject to the following conditions: 339 | 340 | The above copyright notice and this permission notice shall be included in all 341 | copies or substantial portions of the Software. 342 | 343 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 344 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 345 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 346 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 347 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 348 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 349 | SOFTWARE. 350 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'colorize' 2 | require 'fileutils' 3 | 4 | require_relative 'generator/lib/generator' 5 | 6 | task :default do 7 | puts "[Parse] Parsing JSON".yellow 8 | table = parse_json('property.json') 9 | puts "[Parse] Add superclass relation".green 10 | add_superklass_relation(table) 11 | puts "[Parse] Fix method setter and getter".green 12 | handle_method(table) 13 | xcode_proj_file = find_xcodeproj('.') 14 | basename = File.basename(xcode_proj_file) 15 | production = basename.start_with?('Pod') 16 | puts "[Generate] Start to generates UIKit files".yellow 17 | path = if production then 'DKNightVersion' else '.' end 18 | files = objc_code_generator(table, path) 19 | json_file_path = File.join('generator', 'lib', 'generator', 'json', 'project.json') 20 | File.write json_file_path, files.to_json 21 | 22 | puts "[Link] Find pbxproj file path".yellow 23 | puts "[Link] pbxproj is at '#{xcode_proj_file}'".green 24 | puts "[Link] Linking to xcodeproj".yellow 25 | add_files_to_project(xcode_proj_file, json_file_path) 26 | 27 | # remove null source files in project.pbxproj 28 | puts "[Link] Refine project.pbxproj file".yellow 29 | output_file = 'tmp' 30 | input_file = File.join(xcode_proj_file, "project.pbxproj") 31 | File.open(output_file, "w") do |out_file| 32 | File.foreach(input_file) do |line| 33 | out_file.puts line unless line.match("(null)") 34 | end 35 | end 36 | 37 | FileUtils.mv(output_file, input_file) 38 | 39 | puts "[DKNightVersion] has already generate all files".green 40 | end 41 | -------------------------------------------------------------------------------- /fastlane/Fastfile: -------------------------------------------------------------------------------- 1 | fastlane_version "1.70.0" 2 | 3 | default_platform :ios 4 | 5 | # Fastfile 6 | desc "Release new version" 7 | lane :release do |options| 8 | target_version = options[:version] 9 | raise "The version is missed." if target_version.nil? 10 | ensure_git_branch 11 | ensure_git_status_clean 12 | # scan 13 | 14 | sync_build_number_to_git 15 | increment_version_number(version_number: target_version) 16 | 17 | version_bump_podspec(path: "DKNightVersion.podspec", 18 | version_number: target_version) 19 | git_commit_all(message: "Bump version to #{target_version}") 20 | add_git_tag tag: target_version 21 | push_to_git_remote 22 | pod_push 23 | end 24 | 25 | -------------------------------------------------------------------------------- /fastlane/README.md: -------------------------------------------------------------------------------- 1 | fastlane documentation 2 | ================ 3 | # Installation 4 | 5 | Make sure you have the latest version of the Xcode command line tools installed: 6 | 7 | ``` 8 | xcode-select --install 9 | ``` 10 | 11 | ## Choose your installation method: 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 |
Homebrew 16 | Installer Script 17 | Rubygems 18 |
macOSmacOSmacOS or Linux with Ruby 2.0.0 or above
brew cask install fastlaneDownload the zip file. Then double click on the install script (or run it in a terminal window).sudo gem install fastlane -NV
30 | # Available Actions 31 | ### release 32 | ``` 33 | fastlane release 34 | ``` 35 | Release new version 36 | 37 | ---- 38 | 39 | This README.md is auto-generated and will be re-generated every time [fastlane](https://fastlane.tools) is run. 40 | More information about fastlane can be found on [fastlane.tools](https://fastlane.tools). 41 | The documentation of fastlane can be found on [docs.fastlane.tools](https://docs.fastlane.tools). 42 | -------------------------------------------------------------------------------- /fastlane/actions/git_commit_all.rb: -------------------------------------------------------------------------------- 1 | module Fastlane 2 | module Actions 3 | class GitCommitAllAction < Action 4 | def self.run(params) 5 | Actions.sh "git commit -am \"#{params[:message]}\"" 6 | end 7 | 8 | ##################################################### 9 | # @!group Documentation 10 | ##################################################### 11 | 12 | def self.description 13 | "Commit all unsaved changes to git." 14 | end 15 | 16 | def self.available_options 17 | [ 18 | FastlaneCore::ConfigItem.new(key: :message, 19 | env_name: "FL_GIT_COMMIT_ALL", 20 | description: "The git message for the commit", 21 | is_string: true) 22 | ] 23 | end 24 | 25 | def self.is_supported?(platform) 26 | true 27 | end 28 | end 29 | end 30 | end 31 | 32 | -------------------------------------------------------------------------------- /fastlane/actions/sync_build_number_to_git.rb: -------------------------------------------------------------------------------- 1 | module Fastlane 2 | module Actions 3 | module SharedValues 4 | BUILD_NUMBER = :BUILD_NUMBER 5 | end 6 | class SyncBuildNumberToGitAction < Action 7 | def self.is_git? 8 | Actions.sh 'git rev-parse HEAD' 9 | return true 10 | rescue 11 | return false 12 | end 13 | 14 | def self.run(params) 15 | if is_git? 16 | command = 'git rev-list HEAD --count' 17 | else 18 | raise "Not in a git repository." 19 | end 20 | build_number = (Actions.sh command).strip 21 | Fastlane::Actions::IncrementBuildNumberAction.run(build_number: build_number) 22 | Actions.lane_context[SharedValues::BUILD_NUMBER] = build_number 23 | end 24 | 25 | def self.output 26 | [ 27 | ['BUILD_NUMBER', 'The new build number'] 28 | ] 29 | end 30 | end 31 | end 32 | end 33 | 34 | -------------------------------------------------------------------------------- /generator/lib/generator.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | require_relative 'generator/render' 4 | require_relative 'generator/parser' 5 | require_relative 'generator/xcodeproj' 6 | require_relative 'generator/project' 7 | 8 | -------------------------------------------------------------------------------- /generator/lib/generator/json/method.json: -------------------------------------------------------------------------------- 1 | { 2 | "UIButton": 3 | { 4 | "titleColor": 5 | { 6 | "getter": "currentTitleColor", 7 | "setter": "setTitleColor:(UIColor*)titleColor forState:(UIControlState)state", 8 | "parameter": "UIControlStateNormal" 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /generator/lib/generator/json/project.json: -------------------------------------------------------------------------------- 1 | ["DKNightVersion/UIKit/UIView+Night.h","DKNightVersion/UIKit/UIView+Night.m","DKNightVersion/UIKit/UILabel+Night.h","DKNightVersion/UIKit/UILabel+Night.m","DKNightVersion/UIKit/UINavigationBar+Night.h","DKNightVersion/UIKit/UINavigationBar+Night.m","DKNightVersion/UIKit/UITabBar+Night.h","DKNightVersion/UIKit/UITabBar+Night.m","DKNightVersion/UIKit/UIBarButtonItem+Night.h","DKNightVersion/UIKit/UIBarButtonItem+Night.m","DKNightVersion/UIKit/UITableView+Night.h","DKNightVersion/UIKit/UITableView+Night.m","DKNightVersion/UIKit/UITextView+Night.h","DKNightVersion/UIKit/UITextView+Night.m","DKNightVersion/UIKit/UITextField+Night.h","DKNightVersion/UIKit/UITextField+Night.m","DKNightVersion/UIKit/UIControl+Night.h","DKNightVersion/UIKit/UIControl+Night.m","DKNightVersion/UIKit/UIToolbar+Night.h","DKNightVersion/UIKit/UIToolbar+Night.m","DKNightVersion/UIKit/UISwitch+Night.h","DKNightVersion/UIKit/UISwitch+Night.m","DKNightVersion/UIKit/UISlider+Night.h","DKNightVersion/UIKit/UISlider+Night.m","DKNightVersion/UIKit/UISearchBar+Night.h","DKNightVersion/UIKit/UISearchBar+Night.m","DKNightVersion/UIKit/UIProgressView+Night.h","DKNightVersion/UIKit/UIProgressView+Night.m","DKNightVersion/UIKit/UIPageControl+Night.h","DKNightVersion/UIKit/UIPageControl+Night.m"] -------------------------------------------------------------------------------- /generator/lib/generator/json/superklass.json: -------------------------------------------------------------------------------- 1 | { 2 | "UIView": 3 | [ 4 | "UILabel", 5 | "UIControl", 6 | "UINavigationBar", 7 | "UITabBar", 8 | "UIScrollView", 9 | "UITableViewCell", 10 | "UIImageView", 11 | "UIProgressView" 12 | ], 13 | "UIControl": 14 | [ 15 | "UIButton", 16 | "UITextField", 17 | "UISwitch", 18 | "UISegmentedControl" 19 | ], 20 | "UIScrollView": 21 | [ 22 | "UITableView", 23 | "UITextView" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /generator/lib/generator/model/objc_class.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | class ObjcClass 4 | attr_accessor :name, :properties, :superklass 5 | attr_reader :all_properties, :superklass_name 6 | 7 | #def initialize(name, superklass_name, properties = []) 8 | # @name = name 9 | # @superklass_name = superklass_name 10 | # @properties = properties 11 | #end 12 | def initialize(name, properties = []) 13 | @name = name 14 | @properties = properties 15 | end 16 | 17 | def header_name 18 | "#{name}+Night.h" 19 | end 20 | 21 | def imp_name 22 | "#{name}+Night.m" 23 | end 24 | 25 | def all_properties 26 | p = properties.dup 27 | name = p.map { |property| property.name } 28 | k = superklass 29 | while k 30 | superklass.properties.each do |property| 31 | p << property if !name.find_index(property.name) 32 | end 33 | k = k.superklass 34 | name = p.map { |property| property.name } 35 | end 36 | p.uniq 37 | end 38 | 39 | def superklass_name 40 | if superklass 41 | superklass.name 42 | else 43 | nil 44 | end 45 | end 46 | 47 | 48 | def all_superklass_name 49 | k = [] 50 | return if !superklass_name 51 | s = superklass 52 | while s 53 | k << s.name 54 | s = s.superklass 55 | end 56 | k 57 | end 58 | 59 | private 60 | 61 | end 62 | -------------------------------------------------------------------------------- /generator/lib/generator/model/objc_property.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | class ObjcProperty 4 | attr_accessor :name, :type, :getter, :setter, :parameter 5 | 6 | def initialize args 7 | args.each do |k,v| 8 | instance_variable_set("@#{k}", v) unless v.nil? 9 | end 10 | @type ||= "UIColor *" 11 | @setter ||= "set#{cap_name}:" 12 | @getter ||= "#{name}" 13 | end 14 | 15 | def cap_name 16 | @name[0].upcase + @name[1..-1] 17 | end 18 | 19 | def setter_selector_name 20 | setter.split().map { |s| (/.*:/).match(s).to_s }.join 21 | end 22 | 23 | def set_color_method(color) 24 | s = setter.split(' ').map { |str| (/.*:/).match(str).to_s } 25 | s.first.concat(color) 26 | s[1].concat(parameter) unless parameter.nil? 27 | s.join(' ') 28 | end 29 | 30 | end 31 | -------------------------------------------------------------------------------- /generator/lib/generator/parser.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | 3 | require_relative 'model/objc_property' 4 | require_relative 'model/objc_class' 5 | 6 | def parse_json(file) 7 | property_json = JSON.parse File.read(file) 8 | property_json.map do |klass, properties| 9 | ObjcClass.new(klass, properties.map { |property| ObjcProperty.new(name: property) }) 10 | end 11 | end 12 | 13 | def add_superklass_relation(table) 14 | table.each do |first_klass| 15 | table.each do |second_klass| 16 | if is_superklass(first_klass.name, second_klass.name) 17 | # subklass's superklass property is nil or the new superklass is more closer than 18 | # original one. 19 | second_klass.superklass = first_klass if second_klass.superklass.nil? || 20 | is_superklass(second_klass.superklass.name, first_klass.name) 21 | end 22 | end 23 | end 24 | table 25 | end 26 | 27 | def handle_method(table) 28 | method_json = JSON.parse File.read('generator/lib/generator/json/method.json') 29 | table.each do |klass| 30 | if method_json[klass.name] 31 | klass.properties.each do |property| 32 | if method_json[klass.name][property.name] 33 | property_json = method_json[klass.name][property.name] 34 | property.getter = property_json['getter'] 35 | property.setter = property_json['setter'] 36 | property.parameter = property_json['parameter'] 37 | end 38 | end 39 | end 40 | end 41 | end 42 | 43 | def is_superklass(superklass, subklass) 44 | superklass_json = JSON.parse File.read('generator/lib/generator/json/superklass.json') 45 | subklass_list = superklass_json[superklass] 46 | if subklass_list 47 | if subklass_list.find_index(subklass) 48 | return true 49 | else 50 | subklass_list.inject(false) do |memo, sub| 51 | memo || is_superklass(sub, subklass) 52 | end 53 | end 54 | else 55 | return false 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /generator/lib/generator/project.rb: -------------------------------------------------------------------------------- 1 | require 'xcodeproj' 2 | require 'json' 3 | 4 | def add_files_to_project(path, json_path) 5 | production = File.basename(path).start_with?('Pod') 6 | json = JSON.parse File.read(json_path) 7 | project = Xcodeproj::Project.open(path) 8 | target = get_target(project, production) 9 | 10 | group_path = get_group_name(production) 11 | uikit_group = project.main_group.find_subpath(group_path, true) 12 | uikit_group.clear 13 | uikit_group.set_source_tree('SOURCE_ROOT') 14 | clear_target(target) 15 | 16 | file_refs = [] 17 | json.each do |f| 18 | unless uikit_group.find_file_by_path(f) 19 | file_ref = uikit_group.new_reference(f) 20 | file_refs << file_ref 21 | end 22 | end 23 | 24 | target.add_file_references(file_refs) 25 | 26 | project.save 27 | end 28 | 29 | 30 | def get_target(project, production) 31 | if production 32 | project.targets.reduce(project.targets.first) do |init, t| 33 | puts "[Find] Find target #{t}" 34 | if t.to_s.include? 'DKNightVersion' 35 | init = t 36 | end 37 | end 38 | else 39 | project.targets.first 40 | end 41 | end 42 | 43 | def get_group_name(production) 44 | if production 45 | 'Pods/DKNightVersion/UIKit' 46 | else 47 | 'DKNightVersion/Pod/Classes/UIKit' 48 | end 49 | end 50 | 51 | def should_remove(file_name) 52 | return false if file_name.match('UIButton') or file_name.match('UIImageView') 53 | /UI[a-zA-Z]+\+(?:[a-zA-Z]+?|Night)\.[hm]/.match(file_name) 54 | end 55 | 56 | def clear_target(target) 57 | target.source_build_phase.files_references.each do |file_ref| 58 | if file_ref != nil && should_remove(file_ref.name) 59 | target.source_build_phase.remove_file_reference(file_ref) 60 | end 61 | end 62 | target.headers_build_phase.files_references.each do |file_ref| 63 | if file_ref != nil && should_remove(file_ref.name) 64 | target.headers_build_phase.remove_file_reference(file_ref) 65 | end 66 | end 67 | end 68 | -------------------------------------------------------------------------------- /generator/lib/generator/render.rb: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | require 'fileutils' 4 | require 'erb' 5 | require 'ostruct' 6 | 7 | require_relative 'xcodeproj' 8 | 9 | class ErbalT < OpenStruct 10 | def self.render_from_hash(t, h) 11 | ErbalT.new(h).render(t) 12 | end 13 | 14 | def render(template) 15 | ERB.new(template).result(binding) 16 | end 17 | end 18 | 19 | def render(template, klass, property=nil) 20 | erb = File.open(template).read 21 | if property.nil? 22 | ErbalT::render_from_hash(erb, { klass: klass }) 23 | else 24 | ErbalT::render_from_hash(erb, { klass: klass, property: property }) 25 | end 26 | end 27 | 28 | def objc_code_generator(klasses, p='.') 29 | groups = [] 30 | 31 | template_folder = File.join('generator', 'lib', 'generator', 'template') 32 | color_header = File.join(template_folder, 'color.h.erb') 33 | color_imp = File.join(template_folder, 'color.m.erb') 34 | 35 | relative_path = File.join('DKNightVersion', 'UIKit') 36 | FileUtils.rm_rf(relative_path) 37 | FileUtils.mkdir_p(relative_path) 38 | klasses.each do |klass| 39 | groups << File.join(relative_path, klass.header_name) 40 | groups << File.join(relative_path, klass.imp_name) 41 | 42 | header_file_path = File.join(relative_path, klass.header_name) 43 | imp_file_path = File.join(relative_path, klass.imp_name) 44 | 45 | puts "[Generate] Generating #{header_file_path}" 46 | File.write header_file_path, render(color_header, klass) 47 | puts "[Generate] Generating #{imp_file_path}" 48 | File.write imp_file_path, render(color_imp, klass) 49 | end 50 | groups 51 | end 52 | 53 | def has_property(klass, name) 54 | while klass 55 | klass.properties.each do |property| 56 | if property.name == name 57 | return property 58 | end 59 | end 60 | klass = klass.superklass 61 | end 62 | return nil 63 | end 64 | 65 | 66 | -------------------------------------------------------------------------------- /generator/lib/generator/template/color.h.erb: -------------------------------------------------------------------------------- 1 | // 2 | // <%= klass.name %>+Night.h 3 | // <%= klass.name %>+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import 12 | #import "NSObject+Night.h" 13 | 14 | @interface <%= klass.name %> (Night) 15 | 16 | <% klass.properties.each do |property| %><%= "@property (nonatomic, copy, setter = dk_set#{property.cap_name}Picker:) DKColorPicker dk_#{property.name}Picker;\n"%><% end %> 17 | @end 18 | -------------------------------------------------------------------------------- /generator/lib/generator/template/color.m.erb: -------------------------------------------------------------------------------- 1 | // 2 | // <%= klass.name %>+Night.m 3 | // <%= klass.name %>+Night 4 | // 5 | // Copyright (c) 2015 Draveness. All rights reserved. 6 | // 7 | // These files are generated by ruby script, if you want to modify code 8 | // in this file, you are supposed to update the ruby code, run it and 9 | // test it. And finally open a pull request. 10 | 11 | #import "<%= klass.name %>+Night.h" 12 | #import "DKNightVersionManager.h" 13 | #import 14 | 15 | @interface <%= klass.name %> () 16 | 17 | @property (nonatomic, strong) NSMutableDictionary *pickers; 18 | 19 | @end 20 | 21 | @implementation <%= klass.name %> (Night) 22 | 23 | <% klass.properties.each do |property| %><%= """ 24 | - (DKColorPicker)dk_#{property.name}Picker { 25 | return objc_getAssociatedObject(self, @selector(dk_#{property.name}Picker)); 26 | } 27 | 28 | - (void)dk_set#{property.cap_name}Picker:(DKColorPicker)picker { 29 | objc_setAssociatedObject(self, @selector(dk_#{property.name}Picker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); 30 | self.#{property.name} = picker(self.dk_manager.themeVersion); 31 | [self.pickers setValue:[picker copy] forKey:@\"#{property.setter}\"]; 32 | } 33 | """ %><% end %> 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /generator/lib/generator/xcodeproj.rb: -------------------------------------------------------------------------------- 1 | def find_xcodeproj(path) 2 | Dir.foreach(path) do |f| 3 | return File.join path, f if File.extname(f) == ".xcodeproj" 4 | end 5 | find_xcodeproj(File.join '..', path) 6 | end 7 | 8 | def find_pbxproj(path) 9 | xcodeproj = find_xcodeproj(path) 10 | Dir.foreach(xcodeproj) do |f| 11 | return File.join xcodeproj, f if File.extname(f) == ".pbxproj" 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /images/Banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/draveness/DKNightVersion/a59ad0b5a9b4c15ba18f3bae30c2f61e542f2970/images/Banner.png -------------------------------------------------------------------------------- /images/DKNightVersion.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/draveness/DKNightVersion/a59ad0b5a9b4c15ba18f3bae30c2f61e542f2970/images/DKNightVersion.gif -------------------------------------------------------------------------------- /images/add_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/draveness/DKNightVersion/a59ad0b5a9b4c15ba18f3bae30c2f61e542f2970/images/add_file.png -------------------------------------------------------------------------------- /images/target.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/draveness/DKNightVersion/a59ad0b5a9b4c15ba18f3bae30c2f61e542f2970/images/target.png -------------------------------------------------------------------------------- /metamacros.h: -------------------------------------------------------------------------------- 1 | ../../../DKNightVersion/DKNightVersion/extobjc/metamacros.h -------------------------------------------------------------------------------- /property.json: -------------------------------------------------------------------------------- 1 | { 2 | "UIView": 3 | [ 4 | "backgroundColor", 5 | "tintColor" 6 | ], 7 | "UILabel": 8 | [ 9 | "textColor", 10 | "shadowColor", 11 | "highlightedTextColor" 12 | ], 13 | "UINavigationBar": 14 | [ 15 | "barTintColor", 16 | "tintColor" 17 | ], 18 | "UITabBar": 19 | [ 20 | "barTintColor" 21 | ], 22 | "UIBarButtonItem": 23 | [ 24 | "tintColor" 25 | ], 26 | "UITableView": 27 | [ 28 | "separatorColor", 29 | "sectionIndexColor", 30 | "sectionIndexBackgroundColor", 31 | "sectionIndexTrackingBackgroundColor" 32 | ], 33 | "UITextView": 34 | [ 35 | "textColor" 36 | ], 37 | "UITextField": 38 | [ 39 | "textColor" 40 | ], 41 | "UIControl": 42 | [ 43 | "tintColor" 44 | ], 45 | "UIToolbar": 46 | [ 47 | "barTintColor" 48 | ], 49 | "UISwitch": 50 | [ 51 | "onTintColor", 52 | "thumbTintColor" 53 | ], 54 | "UISlider": 55 | [ 56 | "minimumTrackTintColor", 57 | "maximumTrackTintColor", 58 | "thumbTintColor" 59 | ], 60 | "UISearchBar": 61 | [ 62 | "barTintColor" 63 | ], 64 | "UIProgressView": 65 | [ 66 | "progressTintColor", 67 | "trackTintColor" 68 | ], 69 | "UIPageControl": 70 | [ 71 | "pageIndicatorTintColor", 72 | "currentPageIndicatorTintColor" 73 | ] 74 | } 75 | --------------------------------------------------------------------------------