Commit 9f98abc7 cgx

配置CocoaPods

1 个父辈 e60b06ee
正在显示 149 个修改的文件 包含 3953 行增加33 行删除
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>HOST_URL</key>
<string>${HOST_URL}</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
</dict>
</dict>
</plist>
# Uncomment the next line to define a global platform for your project
# platform :ios, '9.0'
platform :ios, '11.0'
target 'DreamSleep' do
# Comment the next line if you don't want to use dynamic frameworks
use_frameworks!
# Pods for DreamSleep
pod 'YTKNetwork', '~> 3.0.6'
pod 'DKNightVersion', '~> 2.4.3'
end
# AFNetworking (4.0.1)
# YTKNetwork (3.0.6)
# DKNightVersion (2.4.3)
PODS:
- AFNetworking/NSURLSession (4.0.1):
- AFNetworking/Reachability
- AFNetworking/Security
- AFNetworking/Serialization
- AFNetworking/Reachability (4.0.1)
- AFNetworking/Security (4.0.1)
- AFNetworking/Serialization (4.0.1)
- DKNightVersion (2.4.3):
- DKNightVersion/Core (= 2.4.3)
- DKNightVersion/CoreAnimation (= 2.4.3)
- DKNightVersion/UIKit (= 2.4.3)
- DKNightVersion/Core (2.4.3):
- DKNightVersion/Core/DeallocBlockExecutor (= 2.4.3)
- DKNightVersion/Core/extobjc (= 2.4.3)
- DKNightVersion/Core/DeallocBlockExecutor (2.4.3)
- DKNightVersion/Core/extobjc (2.4.3)
- DKNightVersion/CoreAnimation (2.4.3):
- DKNightVersion/Core
- DKNightVersion/UIKit (2.4.3):
- DKNightVersion/Core
- YTKNetwork (3.0.6):
- AFNetworking/NSURLSession (~> 4.0)
DEPENDENCIES:
- DKNightVersion (~> 2.4.3)
- YTKNetwork (~> 3.0.6)
SPEC REPOS:
trunk:
- AFNetworking
- DKNightVersion
- YTKNetwork
SPEC CHECKSUMS:
AFNetworking: 7864c38297c79aaca1500c33288e429c3451fdce
DKNightVersion: eaa80cc4014b4bae7d4b535fd87ecc6a3c2767b3
YTKNetwork: c16be90b06be003de9e9cd0d3b187cc8eaf35c04
PODFILE CHECKSUM: f640463a1ebbe4ec2fcd53457d010319e70f41db
COCOAPODS: 1.11.3
// AFCompatibilityMacros.h
// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#ifndef AFCompatibilityMacros_h
#define AFCompatibilityMacros_h
#ifdef API_AVAILABLE
#define AF_API_AVAILABLE(...) API_AVAILABLE(__VA_ARGS__)
#else
#define AF_API_AVAILABLE(...)
#endif // API_AVAILABLE
#ifdef API_UNAVAILABLE
#define AF_API_UNAVAILABLE(...) API_UNAVAILABLE(__VA_ARGS__)
#else
#define AF_API_UNAVAILABLE(...)
#endif // API_UNAVAILABLE
#if __has_warning("-Wunguarded-availability-new")
#define AF_CAN_USE_AT_AVAILABLE 1
#else
#define AF_CAN_USE_AT_AVAILABLE 0
#endif
#if ((__IPHONE_OS_VERSION_MAX_ALLOWED && __IPHONE_OS_VERSION_MAX_ALLOWED < 100000) || (__MAC_OS_VERSION_MAX_ALLOWED && __MAC_OS_VERSION_MAX_ALLOWED < 101200) ||(__WATCH_OS_MAX_VERSION_ALLOWED && __WATCH_OS_MAX_VERSION_ALLOWED < 30000) ||(__TV_OS_MAX_VERSION_ALLOWED && __TV_OS_MAX_VERSION_ALLOWED < 100000))
#define AF_CAN_INCLUDE_SESSION_TASK_METRICS 0
#else
#define AF_CAN_INCLUDE_SESSION_TASK_METRICS 1
#endif
#endif /* AFCompatibilityMacros_h */
// AFNetworkReachabilityManager.h
// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import <Foundation/Foundation.h>
#if !TARGET_OS_WATCH
#import <SystemConfiguration/SystemConfiguration.h>
typedef NS_ENUM(NSInteger, AFNetworkReachabilityStatus) {
AFNetworkReachabilityStatusUnknown = -1,
AFNetworkReachabilityStatusNotReachable = 0,
AFNetworkReachabilityStatusReachableViaWWAN = 1,
AFNetworkReachabilityStatusReachableViaWiFi = 2,
};
NS_ASSUME_NONNULL_BEGIN
/**
`AFNetworkReachabilityManager` monitors the reachability of domains, and addresses for both WWAN and WiFi network interfaces.
Reachability can be used to determine background information about why a network operation failed, or to trigger a network operation retrying when a connection is established. It should not be used to prevent a user from initiating a network request, as it's possible that an initial request may be required to establish reachability.
See Apple's Reachability Sample Code ( https://developer.apple.com/library/ios/samplecode/reachability/ )
@warning Instances of `AFNetworkReachabilityManager` must be started with `-startMonitoring` before reachability status can be determined.
*/
@interface AFNetworkReachabilityManager : NSObject
/**
The current network reachability status.
*/
@property (readonly, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
/**
Whether or not the network is currently reachable.
*/
@property (readonly, nonatomic, assign, getter = isReachable) BOOL reachable;
/**
Whether or not the network is currently reachable via WWAN.
*/
@property (readonly, nonatomic, assign, getter = isReachableViaWWAN) BOOL reachableViaWWAN;
/**
Whether or not the network is currently reachable via WiFi.
*/
@property (readonly, nonatomic, assign, getter = isReachableViaWiFi) BOOL reachableViaWiFi;
///---------------------
/// @name Initialization
///---------------------
/**
Returns the shared network reachability manager.
*/
+ (instancetype)sharedManager;
/**
Creates and returns a network reachability manager with the default socket address.
@return An initialized network reachability manager, actively monitoring the default socket address.
*/
+ (instancetype)manager;
/**
Creates and returns a network reachability manager for the specified domain.
@param domain The domain used to evaluate network reachability.
@return An initialized network reachability manager, actively monitoring the specified domain.
*/
+ (instancetype)managerForDomain:(NSString *)domain;
/**
Creates and returns a network reachability manager for the socket address.
@param address The socket address (`sockaddr_in6`) used to evaluate network reachability.
@return An initialized network reachability manager, actively monitoring the specified socket address.
*/
+ (instancetype)managerForAddress:(const void *)address;
/**
Initializes an instance of a network reachability manager from the specified reachability object.
@param reachability The reachability object to monitor.
@return An initialized network reachability manager, actively monitoring the specified reachability.
*/
- (instancetype)initWithReachability:(SCNetworkReachabilityRef)reachability NS_DESIGNATED_INITIALIZER;
/**
* Unavailable initializer
*/
+ (instancetype)new NS_UNAVAILABLE;
/**
* Unavailable initializer
*/
- (instancetype)init NS_UNAVAILABLE;
///--------------------------------------------------
/// @name Starting & Stopping Reachability Monitoring
///--------------------------------------------------
/**
Starts monitoring for changes in network reachability status.
*/
- (void)startMonitoring;
/**
Stops monitoring for changes in network reachability status.
*/
- (void)stopMonitoring;
///-------------------------------------------------
/// @name Getting Localized Reachability Description
///-------------------------------------------------
/**
Returns a localized string representation of the current network reachability status.
*/
- (NSString *)localizedNetworkReachabilityStatusString;
///---------------------------------------------------
/// @name Setting Network Reachability Change Callback
///---------------------------------------------------
/**
Sets a callback to be executed when the network availability of the `baseURL` host changes.
@param block A block object to be executed when the network availability of the `baseURL` host changes.. This block has no return value and takes a single argument which represents the various reachability states from the device to the `baseURL`.
*/
- (void)setReachabilityStatusChangeBlock:(nullable void (^)(AFNetworkReachabilityStatus status))block;
@end
///----------------
/// @name Constants
///----------------
/**
## Network Reachability
The following constants are provided by `AFNetworkReachabilityManager` as possible network reachability statuses.
enum {
AFNetworkReachabilityStatusUnknown,
AFNetworkReachabilityStatusNotReachable,
AFNetworkReachabilityStatusReachableViaWWAN,
AFNetworkReachabilityStatusReachableViaWiFi,
}
`AFNetworkReachabilityStatusUnknown`
The `baseURL` host reachability is not known.
`AFNetworkReachabilityStatusNotReachable`
The `baseURL` host cannot be reached.
`AFNetworkReachabilityStatusReachableViaWWAN`
The `baseURL` host can be reached via a cellular connection, such as EDGE or GPRS.
`AFNetworkReachabilityStatusReachableViaWiFi`
The `baseURL` host can be reached via a Wi-Fi connection.
### Keys for Notification UserInfo Dictionary
Strings that are used as keys in a `userInfo` dictionary in a network reachability status change notification.
`AFNetworkingReachabilityNotificationStatusItem`
A key in the userInfo dictionary in a `AFNetworkingReachabilityDidChangeNotification` notification.
The corresponding value is an `NSNumber` object representing the `AFNetworkReachabilityStatus` value for the current reachability status.
*/
///--------------------
/// @name Notifications
///--------------------
/**
Posted when network reachability changes.
This notification assigns no notification object. The `userInfo` dictionary contains an `NSNumber` object under the `AFNetworkingReachabilityNotificationStatusItem` key, representing the `AFNetworkReachabilityStatus` value for the current network reachability.
@warning In order for network reachability to be monitored, include the `SystemConfiguration` framework in the active target's "Link Binary With Library" build phase, and add `#import <SystemConfiguration/SystemConfiguration.h>` to the header prefix of the project (`Prefix.pch`).
*/
FOUNDATION_EXPORT NSString * const AFNetworkingReachabilityDidChangeNotification;
FOUNDATION_EXPORT NSString * const AFNetworkingReachabilityNotificationStatusItem;
///--------------------
/// @name Functions
///--------------------
/**
Returns a localized string representation of an `AFNetworkReachabilityStatus` value.
*/
FOUNDATION_EXPORT NSString * AFStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus status);
NS_ASSUME_NONNULL_END
#endif
// AFNetworkReachabilityManager.m
// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import "AFNetworkReachabilityManager.h"
#if !TARGET_OS_WATCH
#import <netinet/in.h>
#import <netinet6/in6.h>
#import <arpa/inet.h>
#import <ifaddrs.h>
#import <netdb.h>
NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire.networking.reachability.change";
NSString * const AFNetworkingReachabilityNotificationStatusItem = @"AFNetworkingReachabilityNotificationStatusItem";
typedef void (^AFNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus status);
typedef AFNetworkReachabilityManager * (^AFNetworkReachabilityStatusCallback)(AFNetworkReachabilityStatus status);
NSString * AFStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus status) {
switch (status) {
case AFNetworkReachabilityStatusNotReachable:
return NSLocalizedStringFromTable(@"Not Reachable", @"AFNetworking", nil);
case AFNetworkReachabilityStatusReachableViaWWAN:
return NSLocalizedStringFromTable(@"Reachable via WWAN", @"AFNetworking", nil);
case AFNetworkReachabilityStatusReachableViaWiFi:
return NSLocalizedStringFromTable(@"Reachable via WiFi", @"AFNetworking", nil);
case AFNetworkReachabilityStatusUnknown:
default:
return NSLocalizedStringFromTable(@"Unknown", @"AFNetworking", nil);
}
}
static AFNetworkReachabilityStatus AFNetworkReachabilityStatusForFlags(SCNetworkReachabilityFlags flags) {
BOOL isReachable = ((flags & kSCNetworkReachabilityFlagsReachable) != 0);
BOOL needsConnection = ((flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0);
BOOL canConnectionAutomatically = (((flags & kSCNetworkReachabilityFlagsConnectionOnDemand ) != 0) || ((flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) != 0));
BOOL canConnectWithoutUserInteraction = (canConnectionAutomatically && (flags & kSCNetworkReachabilityFlagsInterventionRequired) == 0);
BOOL isNetworkReachable = (isReachable && (!needsConnection || canConnectWithoutUserInteraction));
AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusUnknown;
if (isNetworkReachable == NO) {
status = AFNetworkReachabilityStatusNotReachable;
}
#if TARGET_OS_IPHONE
else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) {
status = AFNetworkReachabilityStatusReachableViaWWAN;
}
#endif
else {
status = AFNetworkReachabilityStatusReachableViaWiFi;
}
return status;
}
/**
* Queue a status change notification for the main thread.
*
* This is done to ensure that the notifications are received in the same order
* as they are sent. If notifications are sent directly, it is possible that
* a queued notification (for an earlier status condition) is processed after
* the later update, resulting in the listener being left in the wrong state.
*/
static void AFPostReachabilityStatusChange(SCNetworkReachabilityFlags flags, AFNetworkReachabilityStatusCallback block) {
AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags);
dispatch_async(dispatch_get_main_queue(), ^{
AFNetworkReachabilityManager *manager = nil;
if (block) {
manager = block(status);
}
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
NSDictionary *userInfo = @{ AFNetworkingReachabilityNotificationStatusItem: @(status) };
[notificationCenter postNotificationName:AFNetworkingReachabilityDidChangeNotification object:manager userInfo:userInfo];
});
}
static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) {
AFPostReachabilityStatusChange(flags, (__bridge AFNetworkReachabilityStatusCallback)info);
}
static const void * AFNetworkReachabilityRetainCallback(const void *info) {
return Block_copy(info);
}
static void AFNetworkReachabilityReleaseCallback(const void *info) {
if (info) {
Block_release(info);
}
}
@interface AFNetworkReachabilityManager ()
@property (readonly, nonatomic, assign) SCNetworkReachabilityRef networkReachability;
@property (readwrite, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus;
@property (readwrite, nonatomic, copy) AFNetworkReachabilityStatusBlock networkReachabilityStatusBlock;
@end
@implementation AFNetworkReachabilityManager
+ (instancetype)sharedManager {
static AFNetworkReachabilityManager *_sharedManager = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedManager = [self manager];
});
return _sharedManager;
}
+ (instancetype)managerForDomain:(NSString *)domain {
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [domain UTF8String]);
AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];
CFRelease(reachability);
return manager;
}
+ (instancetype)managerForAddress:(const void *)address {
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)address);
AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];
CFRelease(reachability);
return manager;
}
+ (instancetype)manager
{
#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000) || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
struct sockaddr_in6 address;
bzero(&address, sizeof(address));
address.sin6_len = sizeof(address);
address.sin6_family = AF_INET6;
#else
struct sockaddr_in address;
bzero(&address, sizeof(address));
address.sin_len = sizeof(address);
address.sin_family = AF_INET;
#endif
return [self managerForAddress:&address];
}
- (instancetype)initWithReachability:(SCNetworkReachabilityRef)reachability {
self = [super init];
if (!self) {
return nil;
}
_networkReachability = CFRetain(reachability);
self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown;
return self;
}
- (instancetype)init
{
@throw [NSException exceptionWithName:NSGenericException
reason:@"`-init` unavailable. Use `-initWithReachability:` instead"
userInfo:nil];
return nil;
}
- (void)dealloc {
[self stopMonitoring];
if (_networkReachability != NULL) {
CFRelease(_networkReachability);
}
}
#pragma mark -
- (BOOL)isReachable {
return [self isReachableViaWWAN] || [self isReachableViaWiFi];
}
- (BOOL)isReachableViaWWAN {
return self.networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWWAN;
}
- (BOOL)isReachableViaWiFi {
return self.networkReachabilityStatus == AFNetworkReachabilityStatusReachableViaWiFi;
}
#pragma mark -
- (void)startMonitoring {
[self stopMonitoring];
if (!self.networkReachability) {
return;
}
__weak __typeof(self)weakSelf = self;
AFNetworkReachabilityStatusCallback callback = ^(AFNetworkReachabilityStatus status) {
__strong __typeof(weakSelf)strongSelf = weakSelf;
strongSelf.networkReachabilityStatus = status;
if (strongSelf.networkReachabilityStatusBlock) {
strongSelf.networkReachabilityStatusBlock(status);
}
return strongSelf;
};
SCNetworkReachabilityContext context = {0, (__bridge void *)callback, AFNetworkReachabilityRetainCallback, AFNetworkReachabilityReleaseCallback, NULL};
SCNetworkReachabilitySetCallback(self.networkReachability, AFNetworkReachabilityCallback, &context);
SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^{
SCNetworkReachabilityFlags flags;
if (SCNetworkReachabilityGetFlags(self.networkReachability, &flags)) {
AFPostReachabilityStatusChange(flags, callback);
}
});
}
- (void)stopMonitoring {
if (!self.networkReachability) {
return;
}
SCNetworkReachabilityUnscheduleFromRunLoop(self.networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
}
#pragma mark -
- (NSString *)localizedNetworkReachabilityStatusString {
return AFStringFromNetworkReachabilityStatus(self.networkReachabilityStatus);
}
#pragma mark -
- (void)setReachabilityStatusChangeBlock:(void (^)(AFNetworkReachabilityStatus status))block {
self.networkReachabilityStatusBlock = block;
}
#pragma mark - NSKeyValueObserving
+ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
if ([key isEqualToString:@"reachable"] || [key isEqualToString:@"reachableViaWWAN"] || [key isEqualToString:@"reachableViaWiFi"]) {
return [NSSet setWithObject:@"networkReachabilityStatus"];
}
return [super keyPathsForValuesAffectingValueForKey:key];
}
@end
#endif
// AFSecurityPolicy.h
// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import <Foundation/Foundation.h>
#import <Security/Security.h>
typedef NS_ENUM(NSUInteger, AFSSLPinningMode) {
AFSSLPinningModeNone,
AFSSLPinningModePublicKey,
AFSSLPinningModeCertificate,
};
/**
`AFSecurityPolicy` evaluates server trust against pinned X.509 certificates and public keys over secure connections.
Adding pinned SSL certificates to your app helps prevent man-in-the-middle attacks and other vulnerabilities. Applications dealing with sensitive customer data or financial information are strongly encouraged to route all communication over an HTTPS connection with SSL pinning configured and enabled.
*/
NS_ASSUME_NONNULL_BEGIN
@interface AFSecurityPolicy : NSObject <NSSecureCoding, NSCopying>
/**
The criteria by which server trust should be evaluated against the pinned SSL certificates. Defaults to `AFSSLPinningModeNone`.
*/
@property (readonly, nonatomic, assign) AFSSLPinningMode SSLPinningMode;
/**
The certificates used to evaluate server trust according to the SSL pinning mode.
Note that if pinning is enabled, `evaluateServerTrust:forDomain:` will return true if any pinned certificate matches.
@see policyWithPinningMode:withPinnedCertificates:
*/
@property (nonatomic, strong, nullable) NSSet <NSData *> *pinnedCertificates;
/**
Whether or not to trust servers with an invalid or expired SSL certificates. Defaults to `NO`.
*/
@property (nonatomic, assign) BOOL allowInvalidCertificates;
/**
Whether or not to validate the domain name in the certificate's CN field. Defaults to `YES`.
*/
@property (nonatomic, assign) BOOL validatesDomainName;
///-----------------------------------------
/// @name Getting Certificates from the Bundle
///-----------------------------------------
/**
Returns any certificates included in the bundle. If you are using AFNetworking as an embedded framework, you must use this method to find the certificates you have included in your app bundle, and use them when creating your security policy by calling `policyWithPinningMode:withPinnedCertificates`.
@return The certificates included in the given bundle.
*/
+ (NSSet <NSData *> *)certificatesInBundle:(NSBundle *)bundle;
///-----------------------------------------
/// @name Getting Specific Security Policies
///-----------------------------------------
/**
Returns the shared default security policy, which does not allow invalid certificates, validates domain name, and does not validate against pinned certificates or public keys.
@return The default security policy.
*/
+ (instancetype)defaultPolicy;
///---------------------
/// @name Initialization
///---------------------
/**
Creates and returns a security policy with the specified pinning mode.
Certificates with the `.cer` extension found in the main bundle will be pinned. If you want more control over which certificates are pinned, please use `policyWithPinningMode:withPinnedCertificates:` instead.
@param pinningMode The SSL pinning mode.
@return A new security policy.
@see -policyWithPinningMode:withPinnedCertificates:
*/
+ (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode;
/**
Creates and returns a security policy with the specified pinning mode.
@param pinningMode The SSL pinning mode.
@param pinnedCertificates The certificates to pin against.
@return A new security policy.
@see +certificatesInBundle:
@see -pinnedCertificates
*/
+ (instancetype)policyWithPinningMode:(AFSSLPinningMode)pinningMode withPinnedCertificates:(NSSet <NSData *> *)pinnedCertificates;
///------------------------------
/// @name Evaluating Server Trust
///------------------------------
/**
Whether or not the specified server trust should be accepted, based on the security policy.
This method should be used when responding to an authentication challenge from a server.
@param serverTrust The X.509 certificate trust of the server.
@param domain The domain of serverTrust. If `nil`, the domain will not be validated.
@return Whether or not to trust the server.
*/
- (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust
forDomain:(nullable NSString *)domain;
@end
NS_ASSUME_NONNULL_END
///----------------
/// @name Constants
///----------------
/**
## SSL Pinning Modes
The following constants are provided by `AFSSLPinningMode` as possible SSL pinning modes.
enum {
AFSSLPinningModeNone,
AFSSLPinningModePublicKey,
AFSSLPinningModeCertificate,
}
`AFSSLPinningModeNone`
Do not used pinned certificates to validate servers.
`AFSSLPinningModePublicKey`
Validate host certificates against public keys of pinned certificates.
`AFSSLPinningModeCertificate`
Validate host certificates against pinned certificates.
*/
Copyright (c) 2011-2020 Alamofire Software Foundation (http://alamofire.org/)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
//
// DKColorTable.h
// DKNightVersion
//
// Created by Draveness on 15/12/11.
// Copyright © 2015年 DeltaX. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "DKNightVersionManager.h"
/**
* A convinient macro to create DKColorPicker block.
*
* @param key Key for corresponding entry in table
*
* @return DKColorPicker
*/
#define DKColorPickerWithKey(key) [[DKColorTable sharedColorTable] pickerWithKey:@#key]
/**
* DKColorTable is a new feature in 2.x, which providing you a very convinient and
* delightful approach to manage all your color in an iOS project. Besides that, we
* support multiple themes with DKColorTable, change your `DKColorTable.txt` file
* like this:
*
* Ex:
*
* NORMAL NIGHT RED
* #ffffff #343434 #ff0000 BG
* #aaaaaa #313131 #ff0000 SEP
*
* And you can directly change `[DKNightVersionManager sharedManager].themeVersion` to
* what you want, like: `RED` `NORMAL` and `NIGHT`. And trigger to post notification
* and update corresponding color.
*/
@interface DKColorTable : NSObject
/**
* Call `- reloadColorTable` will trigger `DKColorTable` to load this file,
* default is `DKColorTable.txt`. Don't need to call `- reloadColorTable` after
* setting this property, cuz we have already do it for you.
*/
@property (nonatomic, strong) NSString *file;
/**
* An array of DKThemeVersion, order is exactly the same in `file`.
*/
@property (nonatomic, strong, readonly) NSArray<DKThemeVersion *> *themes;
/**
* Return color table instance, you MUST use this method instead of `- init`,
* `- init` method may have negative impact on your performance.
*
* @return An instance of DKColorTable
*/
+ (instancetype)sharedColorTable;
/**
* Reload `file` into memory, and reconstrcut the whole color table. This method
* will clear color table and use current `file` to load color table again.
*/
- (void)reloadColorTable;
/**
* Return a `DKColorPicker` with `key`, but I suggest you use marcho `DKColorPickerWithKey(key)`
* instead of calling this method.
*
* Ex:
*
* NORMAL NIGHT
* #ffffff #343434 BG
* #aaaaaa #313131 SEP
*
* self.view.dk_backgroundColorPicker = DKColorPickerWithKey(BG);
*
* If current themeVersion is NORMAL, view's background color will be set to #ffffff. When theme
* changes, it will automatically reload color from global color table and update current color
* again.
*
* @param key Which indicates the entry you refer to
*
* @return An DKColorPicker block
*/
- (DKColorPicker)pickerWithKey:(NSString *)key;
@end
//
// DKColorTable.m
// DKNightVersion
//
// Created by Draveness on 15/12/11.
// Copyright © 2015年 DeltaX. All rights reserved.
//
#import "DKColorTable.h"
@interface NSString (Trimming)
@end
@implementation NSString (Trimming)
- (NSString *)stringByTrimmingTrailingCharactersInSet:(NSCharacterSet *)characterSet {
NSUInteger location = 0;
NSUInteger length = [self length];
unichar charBuffer[length];
[self getCharacters:charBuffer];
for (; length > 0; length--) {
if (![characterSet characterIsMember:charBuffer[length - 1]]) {
break;
}
}
return [self substringWithRange:NSMakeRange(location, length - location)];
}
@end
@interface DKColorTable ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSMutableDictionary<NSString *, UIColor *> *> *table;
@property (nonatomic, strong, readwrite) NSArray<DKThemeVersion *> *themes;
@end
@implementation DKColorTable
UIColor *DKColorFromRGB(NSUInteger hex) {
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];
}
UIColor *DKColorFromRGBA(NSUInteger hex) {
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)];
}
+ (instancetype)sharedColorTable {
static DKColorTable *sharedInstance = nil;
static dispatch_once_t oncePredicate;
dispatch_once(&oncePredicate, ^{
sharedInstance = [[DKColorTable alloc] init];
sharedInstance.file = @"DKColorTable.txt";
});
return sharedInstance;
}
- (void)reloadColorTable {
// Clear previos color table
self.table = nil;
self.themes = nil;
// Load color table file
NSString *filepath = [[NSBundle mainBundle] pathForResource:self.file.stringByDeletingPathExtension ofType:self.file.pathExtension];
NSError *error;
NSString *fileContents = [NSString stringWithContentsOfFile:filepath
encoding:NSUTF8StringEncoding
error:&error];
if (error)
NSLog(@"Error reading file: %@", error.localizedDescription);
NSLog(@"DKColorTable:\n%@", fileContents);
NSMutableArray *tempEntries = [[fileContents componentsSeparatedByString:@"\n"] mutableCopy];
// Fixed whitespace error in txt file, fix https://github.com/Draveness/DKNightVersion/issues/64
NSMutableArray *entries = [[NSMutableArray alloc] init];
[tempEntries enumerateObjectsUsingBlock:^(NSString * _Nonnull entry, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *trimmingEntry = [entry stringByTrimmingTrailingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
[entries addObject:trimmingEntry];
}];
[entries filterUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]];
[entries removeObjectAtIndex:0]; // Remove theme entry
self.themes = [self themesFromContents:fileContents];
// Add entry to color table
for (NSString *entry in entries) {
NSArray *colors = [self colorsFromEntry:entry];
NSString *keys = [self keyFromEntry:entry];
[self addEntryWithKey:keys colors:colors themes:self.themes];
}
}
- (NSArray *)themesFromContents:(NSString *)content {
NSString *rawThemes = [content componentsSeparatedByString:@"\n"].firstObject;
return [self separateString:rawThemes];
}
- (NSArray *)colorsFromEntry:(NSString *)entry {
NSMutableArray *colors = [[self separateString:entry] mutableCopy];
[colors removeLastObject];
NSMutableArray *result = [@[] mutableCopy];
for (NSString *number in colors) {
[result addObject:[self colorFromString:number]];
}
return result;
}
- (NSString *)keyFromEntry:(NSString *)entry {
return [self separateString:entry].lastObject;
}
- (void)addEntryWithKey:(NSString *)key colors:(NSArray *)colors themes:(NSArray *)themes {
NSParameterAssert(themes.count == colors.count);
__block NSMutableDictionary *themeToColorDictionary = [@{} mutableCopy];
[themes enumerateObjectsUsingBlock:^(NSString * _Nonnull theme, NSUInteger idx, BOOL * _Nonnull stop) {
[themeToColorDictionary setValue:colors[idx] forKey:theme];
}];
[self.table setValue:themeToColorDictionary forKey:key];
}
- (DKColorPicker)pickerWithKey:(NSString *)key {
NSParameterAssert(key);
NSDictionary *themeToColorDictionary = [self.table valueForKey:key];
DKColorPicker picker = ^(DKThemeVersion *themeVersion) {
return [themeToColorDictionary valueForKey:themeVersion];
};
return picker;
}
#pragma mark - Getter/Setter
- (NSMutableDictionary *)table {
if (!_table) {
_table = [[NSMutableDictionary alloc] init];
}
return _table;
}
- (void)setFile:(NSString *)file {
_file = file;
[self reloadColorTable];
}
#pragma mark - Helper
- (UIColor*)colorFromString:(NSString*)hexStr {
hexStr = [hexStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if([hexStr hasPrefix:@"0x"]) {
hexStr = [hexStr substringFromIndex:2];
}
if([hexStr hasPrefix:@"#"]) {
hexStr = [hexStr substringFromIndex:1];
}
NSUInteger hex = [self intFromHexString:hexStr];
if(hexStr.length > 6) {
return DKColorFromRGBA(hex);
}
return DKColorFromRGB(hex);
}
- (NSUInteger)intFromHexString:(NSString *)hexStr {
unsigned int hexInt = 0;
NSScanner *scanner = [NSScanner scannerWithString:hexStr];
[scanner scanHexInt:&hexInt];
return hexInt;
}
- (NSArray *)separateString:(NSString *)string {
NSArray *array = [string componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
return [array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF != ''"]];
}
@end
NORMAL NIGHT RED
#ffffff #343434 #fafafa BG
#aaaaaa #313131 #aaaaaa SEP
#0000ff #ffffff #fa0000 TINT
#000000 #ffffff #000000 TEXT
#ffffff #444444 #ffffff BAR
#f0f0f0 #222222 #dedede HIGHLIGHTED
//
// DKAlpha.h
// DKNightVersion
//
// Created by History on 16/12/10.
// Copyright © 2016年 Draveness. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NSString DKThemeVersion;
typedef CGFloat (^DKAlphaPicker)(DKThemeVersion *themeVersion);
DKAlphaPicker DKAlphaPickerWithAlphas(CGFloat normal, ...);
@interface DKAlpha : NSObject
+ (DKAlphaPicker)alphaPickerWithAlpha:(CGFloat)alpha;
@end
//
// DKAlpha.m
// DKNightVersion
//
// Created by History on 16/12/10.
// Copyright © 2016年 Draveness. All rights reserved.
//
#import "DKAlpha.h"
#import "DKNightVersionManager.h"
#import "DKColorTable.h"
DKAlphaPicker DKAlphaPickerWithAlphas(CGFloat normal, ...) {
NSArray<DKThemeVersion *> *themes = [DKColorTable sharedColorTable].themes;
NSMutableArray<NSNumber *> *alphas = [[NSMutableArray alloc] initWithCapacity:themes.count];
[alphas addObject:@(normal)];
NSUInteger num_args = themes.count - 1;
va_list args;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wvarargs"
va_start(args, num_args);
#pragma clang diagnostic pop
for (NSUInteger i = 0; i < num_args; i++) {
double alpha = va_arg(args, double);
[alphas addObject:@(alpha)];
}
va_end(args);
return ^(DKThemeVersion *themeVersion) {
NSUInteger index = [themes indexOfObject:themeVersion];
return (CGFloat)[alphas[index] floatValue];
};
}
@implementation DKAlpha
+ (DKAlphaPicker)alphaPickerWithAlpha:(CGFloat)alpha {
return ^(DKThemeVersion *themeVersion) {
return alpha;
};
}
@end
//
// DKColor.h
// DKNightVersion
//
// Created by Draveness on 15/12/9.
// Copyright © 2015年 DeltaX. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NSString DKThemeVersion;
typedef UIColor *(^DKColorPicker)(DKThemeVersion *themeVersion);
DKColorPicker DKColorPickerWithRGB(NSUInteger normal, ...);
DKColorPicker DKColorPickerWithColors(UIColor *normalColor, ...);
@interface DKColor : NSObject
+ (DKColorPicker)colorPickerWithUIColor:(UIColor *)color;
+ (DKColorPicker)colorPickerWithWhite:(CGFloat)white alpha:(CGFloat)alpha;
+ (DKColorPicker)colorPickerWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha;
+ (DKColorPicker)colorPickerWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
+ (DKColorPicker)colorPickerWithCGColor:(CGColorRef)cgColor;
+ (DKColorPicker)colorPickerWithPatternImage:(UIImage *)image;
#if __has_include(<CoreImage/CoreImage.h>)
+ (DKColorPicker)colorPickerWithCIColor:(CIColor *)ciColor NS_AVAILABLE_IOS(5_0);
#endif
+ (DKColorPicker)blackColor;
+ (DKColorPicker)darkGrayColor;
+ (DKColorPicker)lightGrayColor;
+ (DKColorPicker)whiteColor;
+ (DKColorPicker)grayColor;
+ (DKColorPicker)redColor;
+ (DKColorPicker)greenColor;
+ (DKColorPicker)blueColor;
+ (DKColorPicker)cyanColor;
+ (DKColorPicker)yellowColor;
+ (DKColorPicker)magentaColor;
+ (DKColorPicker)orangeColor;
+ (DKColorPicker)purpleColor;
+ (DKColorPicker)brownColor;
+ (DKColorPicker)clearColor;
@end
//
// DKColor.m
// DKNightVersion
//
// Created by Draveness on 15/12/9.
// Copyright © 2015年 DeltaX. All rights reserved.
//
#import "DKColor.h"
#import "DKNightVersionManager.h"
#import "DKColorTable.h"
@implementation DKColor
DKColorPicker DKColorPickerWithRGB(NSUInteger normal, ...) {
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];
NSArray<DKThemeVersion *> *themes = [DKColorTable sharedColorTable].themes;
NSMutableArray<UIColor *> *colors = [[NSMutableArray alloc] initWithCapacity:themes.count];
[colors addObject:normalColor];
NSUInteger num_args = themes.count - 1;
va_list rgbs;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wvarargs"
va_start(rgbs, num_args);
#pragma clang diagnostic pop
for (NSUInteger i = 0; i < num_args; i++) {
NSUInteger rgb = va_arg(rgbs, NSUInteger);
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];
[colors addObject:color];
}
va_end(rgbs);
return ^(DKThemeVersion *themeVersion) {
NSUInteger index = [themes indexOfObject:themeVersion];
return colors[index];
};
}
DKColorPicker DKColorPickerWithColors(UIColor *normalColor, ...) {
NSArray<DKThemeVersion *> *themes = [DKColorTable sharedColorTable].themes;
NSMutableArray<UIColor *> *colors = [[NSMutableArray alloc] initWithCapacity:themes.count];
[colors addObject:normalColor];
NSUInteger num_args = themes.count - 1;
va_list colors_list;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wvarargs"
va_start(colors_list, num_args);
#pragma clang diagnostic pop
for (NSUInteger i = 0; i < num_args; i++) {
UIColor *color = va_arg(colors_list, UIColor *);
[colors addObject:color];
}
va_end(colors_list);
return ^(DKThemeVersion *themeVersion) {
NSUInteger index = [themes indexOfObject:themeVersion];
return colors[index];
};
}
+ (DKColorPicker)pickerWithNormalColor:(UIColor *)normalColor nightColor:(UIColor *)nightColor {
return ^(DKThemeVersion *themeVersion) {
return [themeVersion isEqualToString:DKThemeVersionNormal] ? normalColor : nightColor;
};
}
+ (DKColorPicker)colorPickerWithUIColor:(UIColor *)color {
return ^(DKThemeVersion *themeVersion) {
return color;
};
}
+ (DKColorPicker)blackColor {
return [self colorPickerWithUIColor:[UIColor blackColor]];
}
+ (DKColorPicker)darkGrayColor {
return [self colorPickerWithUIColor:[UIColor darkGrayColor]];
}
+ (DKColorPicker)lightGrayColor {
return [self colorPickerWithUIColor:[UIColor lightGrayColor]];
}
+ (DKColorPicker)whiteColor {
return [self colorPickerWithUIColor:[UIColor whiteColor]];
}
+ (DKColorPicker)grayColor {
return [self colorPickerWithUIColor:[UIColor grayColor]];
}
+ (DKColorPicker)redColor {
return [self colorPickerWithUIColor:[UIColor redColor]];
}
+ (DKColorPicker)greenColor {
return [self colorPickerWithUIColor:[UIColor greenColor]];
}
+ (DKColorPicker)blueColor {
return [self colorPickerWithUIColor:[UIColor blueColor]];
}
+ (DKColorPicker)cyanColor {
return [self colorPickerWithUIColor:[UIColor cyanColor]];
}
+ (DKColorPicker)yellowColor {
return [self colorPickerWithUIColor:[UIColor yellowColor]];
}
+ (DKColorPicker)magentaColor {
return [self colorPickerWithUIColor:[UIColor magentaColor]];
}
+ (DKColorPicker)orangeColor {
return [self colorPickerWithUIColor:[UIColor orangeColor]];
}
+ (DKColorPicker)purpleColor {
return [self colorPickerWithUIColor:[UIColor purpleColor]];
}
+ (DKColorPicker)brownColor {
return [self colorPickerWithUIColor:[UIColor brownColor]];
}
+ (DKColorPicker)clearColor {
return [self colorPickerWithUIColor:[UIColor clearColor]];
}
+ (DKColorPicker)colorPickerWithWhite:(CGFloat)white alpha:(CGFloat)alpha {
return [self colorPickerWithUIColor:[UIColor colorWithWhite:white alpha:alpha]];
}
+ (DKColorPicker)colorPickerWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha {
return [self colorPickerWithUIColor:[UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:alpha]];
}
+ (DKColorPicker)colorPickerWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha {
return [self colorPickerWithUIColor:[UIColor colorWithRed:red green:green blue:blue alpha:alpha]];
}
+ (DKColorPicker)colorPickerWithCGColor:(CGColorRef)cgColor {
return [self colorPickerWithUIColor:[UIColor colorWithCGColor:cgColor]];
}
+ (DKColorPicker)colorPickerWithPatternImage:(UIImage *)image {
return [self colorPickerWithUIColor:[UIColor colorWithPatternImage:image]];
}
#if __has_include(<CoreImage/CoreImage.h>)
+ (DKColorPicker)colorPickerWithCIColor:(CIColor *)ciColor NS_AVAILABLE_IOS(5_0) {
return [self colorPickerWithUIColor:[UIColor colorWithCIColor:ciColor]];
}
#endif
@end
//
// DKImage.h
// DKNightVersion
//
// Created by Draveness on 15/12/10.
// Copyright © 2015年 DeltaX. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef NSString DKThemeVersion;
typedef UIImage *(^DKImagePicker)(DKThemeVersion *themeVersion);
/**
* A C function takes an array of images return a image picker, the
* order of the images is just like the themes order in DKColorTable.txt
* file.
*
* @param normalImage Image when current themeVersion is DKThemeVersionNormal
* @param ... Other images, the order is the same as DKColorTable
*
* @return A DKImagePicker
*/
DKImagePicker DKImagePickerWithImages(UIImage *normalImage, ...);
/**
* A C function takes an array of names return a image picker, the
* order of the images is just like the themes order in DKColorTable.txt
* file.
*
* @param normalName Names when current themeVersion is DKThemeVersionNormal
* @param ... Other names, the order is the same as DKColorTable
*
* @return A DKImagePicker
*/
DKImagePicker DKImagePickerWithNames(NSString *normalName, ...);
@interface DKImage : NSObject
/**
* A method takes an array of images return a image picker, the
* order of the images is just like the themes order in DKColorTable.txt
* file.
*
* @param names An array of images
*
* @return A DKImagePicker
*/
+ (DKImagePicker)pickerWithNames:(NSArray<NSString *> *)names;
/**
* A method takes an array of images return a image picker, the
* order of the images is just like the themes order in DKColorTable.txt
* file.
*
* @param images An array of image names
*
* @return A DKImagePicker
*/
+ (DKImagePicker)pickerWithImages:(NSArray<UIImage *> *)images;
/**
* Returns a image picker return the same image no matter what the current
* theme version is
*
* @param name The name for image
*
* @return A DKImagePicker
*/
+ (DKImagePicker)imageNamed:(NSString *)name;
/**
* Returns a image picker return night image when current theme version is
* DKThemeVersionNight, return normal image in other cases.
*
* @param normalImage Normal image
* @param nightImage Image returns when theme version is DKThemeVersionNight
*
* @return A DKImagePicker
*/
+ (DKImagePicker)pickerWithNormalImage:(UIImage *)normalImage nightImage:(UIImage *)nightImage;
@end
//
// DKImage.m
// DKNightVersion
//
// Created by Draveness on 15/12/10.
// Copyright © 2015年 DeltaX. All rights reserved.
//
#import "DKImage.h"
#import "DKNightVersionManager.h"
#import "DKColorTable.h"
@implementation DKImage
DKImagePicker DKImagePickerWithNames(NSString *normalName, ...) {
NSArray<DKThemeVersion *> *themes = [DKColorTable sharedColorTable].themes;
NSMutableArray<NSString *> *names = [[NSMutableArray alloc] initWithCapacity:themes.count];
[names addObject:normalName];
NSUInteger num_args = themes.count - 1;
va_list names_list;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wvarargs"
va_start(names_list, num_args);
#pragma clang diagnostic pop
for (NSUInteger i = 0; i < num_args; i++) {
NSString *name = va_arg(names_list, NSString *);
[names addObject:name];
}
va_end(names_list);
return [DKImage pickerWithNames:names];
}
DKImagePicker DKImagePickerWithImages(UIImage *normalImage, ...) {
NSArray<DKThemeVersion *> *themes = [DKColorTable sharedColorTable].themes;
NSMutableArray<UIImage *> *images = [[NSMutableArray alloc] initWithCapacity:themes.count];
[images addObject:normalImage];
NSUInteger num_args = themes.count - 1;
va_list images_list;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wvarargs"
va_start(images_list, num_args);
#pragma clang diagnostic pop
for (NSUInteger i = 0; i < num_args; i++) {
UIImage *image = va_arg(images_list, UIImage *);
[images addObject:image];
}
va_end(images_list);
return [DKImage pickerWithImages:images];
}
+ (DKImagePicker)pickerWithNormalImage:(UIImage *)normalImage nightImage:(UIImage *)nightImage {
NSParameterAssert(normalImage);
NSParameterAssert(nightImage);
return ^(DKThemeVersion *themeVersion) {
return [themeVersion isEqualToString:DKThemeVersionNight] ? nightImage : normalImage;
};
}
+ (DKImagePicker)pickerWithImage:(UIImage *)image {
return ^(DKThemeVersion *themeVersion) {
return image;
};
}
+ (DKImagePicker)imageNamed:(NSString *)name {
return [self pickerWithImage:[UIImage imageNamed:name]];
}
+ (DKImagePicker)pickerWithNames:(NSArray<NSString *> *)names {
DKColorTable *colorTable = [DKColorTable sharedColorTable];
NSParameterAssert(names.count == colorTable.themes.count);
return ^(DKThemeVersion *themeVersion) {
NSUInteger index = [colorTable.themes indexOfObject:themeVersion];
if (index >= colorTable.themes.count) {
return [UIImage imageNamed:names[[colorTable.themes indexOfObject:DKThemeVersionNormal]]];
}
return [UIImage imageNamed:names[index]];
};
}
+ (DKImagePicker)pickerWithImages:(NSArray<UIImage *> *)images {
DKColorTable *colorTable = [DKColorTable sharedColorTable];
NSParameterAssert(images.count == colorTable.themes.count);
return ^(DKThemeVersion *themeVersion) {
NSUInteger index = [colorTable.themes indexOfObject:themeVersion];
if (index >= colorTable.themes.count) {
return images[[colorTable.themes indexOfObject:DKThemeVersionNormal]];
}
return images[index];
};
}
@end
//
// DKNightVersionManager.h
// DKNightVersionManager
//
// Created by Draveness on 4/14/15.
// Copyright (c) 2015 Draveness. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "DKColor.h"
#import "DKImage.h"
#import "DKAlpha.h"
NS_ASSUME_NONNULL_BEGIN
/**
* DKThemeVersion is just a alias to string, use `- isEqualToString` to
* compare with each `DKThemeVersion` instead of symbol `==`.
*/
typedef NSString DKThemeVersion;
/**
* DKThemeVersionNormal is just a const string @"NORMAL", but use `- isEqualToString:`
* to compare with another string.
*/
extern DKThemeVersion * const DKThemeVersionNormal;
/**
* DKThemeVersionNight is just a const string @"NIGHT", but use `- isEqualToString:`
* to compare with another string.
*/
extern DKThemeVersion * const DKThemeVersionNight;
/**
* This notification will post, every time you change current theme version
* of DKNightVersionManager glbal instance.
*/
extern NSString * const DKNightVersionThemeChangingNotification;
/**
* When change theme version, it will gives us a smooth animation. And this
* is the duration for this animation.
*/
extern CGFloat const DKNightVersionAnimationDuration;
/**
* DKNightVersionManager is the core class for DKNightVersion, it manages all
* the different themes in the color table. Use `- sharedInstance` instead of
* `- init` to get an instance.
*/
@interface DKNightVersionManager : NSObject
/**
* 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`
*/
@property (nonatomic, assign, getter=shouldChangeStatusBar) BOOL changeStatusBar;
/**
* Current ThemeVersion, default is DKThemeVersionNormal, change it to change the global
* theme, this will post `DKNightVersionThemeChangingNotification`, if you want to customize
* your theme you can observe this notification.
*
* Ex:
*
* ```objectivec
* DKNightVersionManager *manager = [DKNightVersionManager sharedManager];
* manager.themeVersion = @"RED"; // DKThemeVersionNormal or DKThemeVersionNight
* ```
*
*/
@property (nonatomic, strong) DKThemeVersion *themeVersion;
/**
* Support keyboard type changes when swiching to DKThemeNight. If this value is YES,
* `keyboardType` for UITextField will change to `UIKeyboardAppearanceDark` only current theme
* version is DKThemeNight. Default is YES.
*/
@property (nonatomic, assign) BOOL supportsKeyboard;
/**
* Return the shared night version manager instance
*
* @return singleton instance for DKNightVersionManager
*/
+ (DKNightVersionManager *)sharedManager;
/**
* Night falling. When nightFalling is called, post `DKNightVersionThemeChangingNotification`.
* You can setup customize with observing the notification. `themeVersion` of the manager will
* be set to `DKNightVersionNight`. This is a convinient method for switching theme the
* `DKThemeVersionNight`.
*/
- (void)nightFalling;
/**
* Dawn coming. When dawnComing is called, post `DKNightVersionThemeChangingNotification`.
* You can setup customize with observing the notification.`themeVersion` of the manager will
* be set to `DKNightVersionNormal`. This is a convinient method for switching theme the
* `DKThemeVersionNormal`.
*/
- (void)dawnComing;
/**
* This method is deprecated, use `- [DKNightVersion sharedManager]` instead
*/
+ (DKNightVersionManager *)sharedNightVersionManager __deprecated_msg("use `- [DKNightVersion sharedManager]` instead");
@end
NS_ASSUME_NONNULL_END
//
// DKNightVersionManager.m
// DKNightVersionManager
//
// Created by Draveness on 4/14/15.
// Copyright (c) 2015 Draveness. All rights reserved.
//
#import "DKNightVersionManager.h"
NSString * const DKThemeVersionNormal = @"NORMAL";
NSString * const DKThemeVersionNight = @"NIGHT";
NSString * const DKNightVersionThemeChangingNotification = @"DKNightVersionThemeChangingNotification";
CGFloat const DKNightVersionAnimationDuration = 0.3;
NSString * const DKNightVersionCurrentThemeVersionKey = @"com.dknightversion.manager.themeversion";
@interface DKNightVersionManager ()
@end
@implementation DKNightVersionManager
+ (DKNightVersionManager *)sharedManager {
static dispatch_once_t once;
static DKNightVersionManager *instance;
dispatch_once(&once, ^{
instance = [self new];
instance.changeStatusBar = YES;
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
DKThemeVersion *themeVersion = [userDefaults valueForKey:DKNightVersionCurrentThemeVersionKey];
themeVersion = themeVersion ?: DKThemeVersionNormal;
instance.themeVersion = themeVersion;
instance.supportsKeyboard = YES;
});
return instance;
}
+ (DKNightVersionManager *)sharedNightVersionManager {
return [self sharedManager];
}
- (void)nightFalling {
self.themeVersion = DKThemeVersionNight;
}
- (void)dawnComing {
self.themeVersion = DKThemeVersionNormal;
}
- (void)setThemeVersion:(DKThemeVersion *)themeVersion {
if ([_themeVersion isEqualToString:themeVersion]) {
// if type does not change, don't execute code below to enhance performance.
return;
}
_themeVersion = themeVersion;
// Save current theme version to user default
[[NSUserDefaults standardUserDefaults] setValue:themeVersion forKey:DKNightVersionCurrentThemeVersionKey];
[[NSNotificationCenter defaultCenter] postNotificationName:DKNightVersionThemeChangingNotification
object:nil];
if (self.shouldChangeStatusBar) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
if ([themeVersion isEqualToString:DKThemeVersionNight]) {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
} else {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}
#pragma clang diagnostic pop
}
}
@end
//
// NSObject+Night.h
// DKNightVersion
//
// Created by Draveness on 15/11/7.
// Copyright © 2015年 DeltaX. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "DKNightVersionManager.h"
@interface NSObject (Night)
/**
* Default global DKNightVersionManager, this property gives us a more
* convinient way to access it.
*/
@property (nonatomic, strong, readonly) DKNightVersionManager *dk_manager;
@end
//
// NSObject+Night.m
// DKNightVersion
//
// Created by Draveness on 15/11/7.
// Copyright © 2015年 DeltaX. All rights reserved.
//
#import "NSObject+Night.h"
#import "NSObject+DeallocBlock.h"
#import <objc/runtime.h>
static void *DKViewDeallocHelperKey;
@interface NSObject ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation NSObject (Night)
- (NSMutableDictionary<NSString *, DKColorPicker> *)pickers {
NSMutableDictionary<NSString *, DKColorPicker> *pickers = objc_getAssociatedObject(self, @selector(pickers));
if (!pickers) {
@autoreleasepool {
// Need to removeObserver in dealloc
if (objc_getAssociatedObject(self, &DKViewDeallocHelperKey) == nil) {
__unsafe_unretained typeof(self) weakSelf = self; // NOTE: need to be __unsafe_unretained because __weak var will be reset to nil in dealloc
id deallocHelper = [self addDeallocBlock:^{
[[NSNotificationCenter defaultCenter] removeObserver:weakSelf];
}];
objc_setAssociatedObject(self, &DKViewDeallocHelperKey, deallocHelper, OBJC_ASSOCIATION_ASSIGN);
}
}
pickers = [[NSMutableDictionary alloc] init];
objc_setAssociatedObject(self, @selector(pickers), pickers, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[[NSNotificationCenter defaultCenter] removeObserver:self name:DKNightVersionThemeChangingNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(night_updateColor) name:DKNightVersionThemeChangingNotification object:nil];
}
return pickers;
}
- (DKNightVersionManager *)dk_manager {
return [DKNightVersionManager sharedManager];
}
- (void)night_updateColor {
[self.pickers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull selector, DKColorPicker _Nonnull picker, BOOL * _Nonnull stop) {
SEL sel = NSSelectorFromString(selector);
id result = picker(self.dk_manager.themeVersion);
[UIView animateWithDuration:DKNightVersionAnimationDuration
animations:^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self performSelector:sel withObject:result];
#pragma clang diagnostic pop
}];
}];
}
@end
//
// CALayer+Night.h
// DKNightVersion
//
// Created by Draveness on 16/1/29.
// Copyright © 2016年 DeltaX. All rights reserved.
//
#import <QuartzCore/QuartzCore.h>
#import "NSObject+Night.h"
@interface CALayer (Night)
@property (nonatomic, copy) DKColorPicker dk_shadowColorPicker;
@property (nonatomic, copy) DKColorPicker dk_borderColorPicker;
@property (nonatomic, copy) DKColorPicker dk_backgroundColorPicker;
@end
//
// CALayer+Night.m
// DKNightVersion
//
// Created by Draveness on 16/1/29.
// Copyright © 2016年 DeltaX. All rights reserved.
//
#import "CALayer+Night.h"
#import <objc/runtime.h>
@interface CALayer ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation CALayer (Night)
- (DKColorPicker)dk_shadowColorPicker {
return objc_getAssociatedObject(self, @selector(dk_shadowColorPicker));
}
- (void)setDk_shadowColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_shadowColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.shadowColor = picker(self.dk_manager.themeVersion).CGColor;
[self.pickers setValue:[picker copy] forKey:NSStringFromSelector(@selector(setShadowColor:))];
}
- (DKColorPicker)dk_borderColorPicker {
return objc_getAssociatedObject(self, @selector(dk_borderColorPicker));
}
- (void)setDk_borderColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_borderColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.borderColor = picker(self.dk_manager.themeVersion).CGColor;
[self.pickers setValue:[picker copy] forKey:NSStringFromSelector(@selector(setBorderColor:))];
}
- (DKColorPicker)dk_backgroundColorPicker {
return objc_getAssociatedObject(self, @selector(dk_backgroundColorPicker));
}
- (void)setDk_backgroundColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_backgroundColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.backgroundColor = picker(self.dk_manager.themeVersion).CGColor;
[self.pickers setValue:[picker copy] forKey:NSStringFromSelector(@selector(setBackgroundColor:))];
}
- (void)night_updateColor {
[self.pickers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull selector, DKColorPicker _Nonnull picker, BOOL * _Nonnull stop) {
CGColorRef result = picker(self.dk_manager.themeVersion).CGColor;
[UIView animateWithDuration:DKNightVersionAnimationDuration
animations:^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if ([selector isEqualToString:NSStringFromSelector(@selector(setShadowColor:))]) {
[self setShadowColor:result];
} else if ([selector isEqualToString:NSStringFromSelector(@selector(setBorderColor:))]) {
[self setBorderColor:result];
} else if ([selector isEqualToString:NSStringFromSelector(@selector(setBackgroundColor:)) ]) {
[self setBackgroundColor:result];
}
#pragma clang diagnostic pop
}];
}];
}
@end
//
// CAShapeLayer+Night.h
// tztMobileApp_HTSC
//
// Created by YeTao on 2016/11/15.
//
//
#import <QuartzCore/QuartzCore.h>
#import "NSObject+Night.h"
@interface CAShapeLayer (Night)
@property (nonatomic, copy) DKColorPicker dk_strokeColorPicker;
@property (nonatomic, copy) DKColorPicker dk_fillColorPicker;
@end
//
// CAShapeLayer+Night.m
// tztMobileApp_HTSC
//
// Created by YeTao on 2016/11/15.
//
//
#import "CAShapeLayer+Night.h"
#import <objc/runtime.h>
@interface CAShapeLayer ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation CAShapeLayer (Night)
- (DKColorPicker)dk_strokeColorPicker {
return objc_getAssociatedObject(self, @selector(dk_strokeColorPicker));
}
- (void)setDk_strokeColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_strokeColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.strokeColor = picker(self.dk_manager.themeVersion).CGColor;
[self.pickers setValue:[picker copy] forKey:NSStringFromSelector(@selector(setStrokeColor:))];
}
- (DKColorPicker)dk_fillColorPicker {
return objc_getAssociatedObject(self, @selector(dk_strokeColorPicker));
}
- (void)setDk_fillColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_fillColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.fillColor = picker(self.dk_manager.themeVersion).CGColor;
[self.pickers setValue:[picker copy] forKey:NSStringFromSelector(@selector(setFillColor:))];
}
- (void)night_updateColor {
[self.pickers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull selector, DKColorPicker _Nonnull picker, BOOL * _Nonnull stop) {
CGColorRef result = picker(self.dk_manager.themeVersion).CGColor;
[UIView animateWithDuration:DKNightVersionAnimationDuration
animations:^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if ([selector isEqualToString:NSStringFromSelector(@selector(setShadowColor:))]) {
[self setShadowColor:result];
} else if ([selector isEqualToString:NSStringFromSelector(@selector(setBorderColor:))]) {
[self setBorderColor:result];
} else if ([selector isEqualToString:NSStringFromSelector(@selector(setBackgroundColor:)) ]) {
[self setBackgroundColor:result];
} else if ([selector isEqualToString:NSStringFromSelector(@selector(setStrokeColor:)) ]) {
[self setStrokeColor:result];
} else if ([selector isEqualToString:NSStringFromSelector(@selector(setFillColor:)) ]) {
[self setFillColor:result];
}
#pragma clang diagnostic pop
}];
}];
}
@end
//
// CoreAnimation+Night.h
// DKNightVersion
//
// Created by Draveness on 16/4/1.
// Copyright © 2016年 DeltaX. All rights reserved.
//
#ifndef CoreAnimation_Night_h
#define CoreAnimation_Night_h
#import "CALayer+Night.h"
#endif /* CoreAnimation_Night_h */
//
// DKNightVersion.h
// DKNightVerision
//
// Created by Draveness on 4/14/15.
// Copyright (c) 2015 Draveness. All rights reserved.
//
#import <UIKit/UIKit.h>
//! Project version number for DKNightVersion.
FOUNDATION_EXPORT double DKNightVersionVersionNumber;
//! Project version string for DKNightVersion.
FOUNDATION_EXPORT const unsigned char DKNightVersionVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <DKNightVersion/PublicHeader.h>
#ifndef _DKNIGHTVERSION_
#define _DKNIGHTVERSION_
#import <objc/runtime.h>
#import <DKNightVersion/DKColor.h>
#import <DKNightVersion/DKImage.h>
#import <DKNightVersion/DKNightVersionManager.h>
#import <DKNightVersion/NSObject+Night.h>
#import <DKNightVersion/DKAlpha.h>
#import <DKNightVersion/DKColorTable.h>
#import <DKNightVersion/CoreAnimation+Night.h>
#import <DKNightVersion/UIBarButtonItem+Night.h>
#import <DKNightVersion/UIControl+Night.h>
#import <DKNightVersion/UILabel+Night.h>
#import <DKNightVersion/UINavigationBar+Night.h>
#import <DKNightVersion/UIPageControl+Night.h>
#import <DKNightVersion/UIProgressView+Night.h>
#import <DKNightVersion/UISearchBar+Night.h>
#import <DKNightVersion/UISlider+Night.h>
#import <DKNightVersion/UISwitch+Night.h>
#import <DKNightVersion/UITabBar+Night.h>
#import <DKNightVersion/UITableView+Night.h>
#import <DKNightVersion/UITextField+Night.h>
#import <DKNightVersion/UITextView+Night.h>
#import <DKNightVersion/UIToolbar+Night.h>
#import <DKNightVersion/UIView+Night.h>
#import <DKNightVersion/UIButton+Night.h>
#import <DKNightVersion/UIImageView+Night.h>
#import <DKNightVersion/metamacros.h>
#import <DKNightVersion/EXTKeyPathCoding.h>
#define _DKSetterWithPROPERTYerty(LOWERCASE) [NSString stringWithFormat:@"set%@:", [[[LOWERCASE substringToIndex:1] uppercaseString] stringByAppendingString:[LOWERCASE substringFromIndex:1]]]
#define pickerify(KLASS, PROPERTY) interface \
KLASS (Night_ ## PROPERTY ## _Picker) \
@property (nonatomic, copy, setter = dk_set ## PROPERTY ## Picker:) DKColorPicker dk_ ## PROPERTY ## Picker; \
@end \
@implementation \
KLASS (Night_ ## PROPERTY ## _Picker) \
- (DKColorPicker)dk_ ## PROPERTY ## Picker { \
return objc_getAssociatedObject(self, @selector(dk_ ## PROPERTY ## Picker)); \
} \
- (void)dk_set ## PROPERTY ## Picker:(DKColorPicker)picker { \
objc_setAssociatedObject(self, @selector(dk_ ## PROPERTY ## Picker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC); \
[self setValue:picker(self.dk_manager.themeVersion) forKeyPath:@keypath(self, PROPERTY)];\
NSMutableDictionary *pickers = [self valueForKeyPath:@"pickers"];\
[pickers setValue:[picker copy] forKey:_DKSetterWithPROPERTYerty(@#PROPERTY)]; \
} \
@end
#endif /* _DKNIGHTVERSION_ */
//
// DeallocBlockExecutor.h
// DKNightVersion
//
// Created by nathanwhy on 16/2/24.
// Copyright © 2016年 Draveness. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface DKDeallocBlockExecutor : NSObject
+ (instancetype)executorWithDeallocBlock:(void (^)())deallocBlock;
@property (nonatomic, copy) void (^deallocBlock)();
@end
//
// DeallocBlockExecutor.m
// DKNightVersion
//
// Created by nathanwhy on 16/2/24.
// Copyright © 2016年 Draveness. All rights reserved.
//
#import "DKDeallocBlockExecutor.h"
@implementation DKDeallocBlockExecutor
+ (instancetype)executorWithDeallocBlock:(void (^)())deallocBlock {
DKDeallocBlockExecutor *o = [DKDeallocBlockExecutor new];
o.deallocBlock = deallocBlock;
return o;
}
- (void)dealloc {
if (self.deallocBlock) {
self.deallocBlock();
self.deallocBlock = nil;
}
}
@end
//
// NSObject+DeallocBlock.h
// DKNightVersion
//
// Created by nathanwhy on 16/2/24.
// Copyright © 2016年 Draveness. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface NSObject (DeallocBlock)
- (id)addDeallocBlock:(void (^)())deallocBlock;
@end
//
// NSObject+DeallocBlock.m
// DKNightVersion
//
// Created by nathanwhy on 16/2/24.
// Copyright © 2016年 Draveness. All rights reserved.
//
#import "NSObject+DeallocBlock.h"
#import "DKDeallocBlockExecutor.h"
#import <objc/runtime.h>
static void *kNSObject_DeallocBlocks;
@implementation NSObject (DeallocBlock)
- (id)addDeallocBlock:(void (^)())deallocBlock {
if (deallocBlock == nil) {
return nil;
}
NSMutableArray *deallocBlocks = objc_getAssociatedObject(self, &kNSObject_DeallocBlocks);
if (deallocBlocks == nil) {
deallocBlocks = [NSMutableArray array];
objc_setAssociatedObject(self, &kNSObject_DeallocBlocks, deallocBlocks, OBJC_ASSOCIATION_RETAIN);
}
// Check if the block is already existed
for (DKDeallocBlockExecutor *executor in deallocBlocks) {
if (executor.deallocBlock == deallocBlock) {
return nil;
}
}
DKDeallocBlockExecutor *executor = [DKDeallocBlockExecutor executorWithDeallocBlock:deallocBlock];
[deallocBlocks addObject:executor];
return executor;
}
@end
//
// UIButton+Night.h
// DKNightVersion
//
// Created by Draveness on 15/12/9.
// Copyright © 2015年 DeltaX. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UIButton (Night)
- (void)dk_setTitleColorPicker:(DKColorPicker)picker forState:(UIControlState)state;
- (void)dk_setBackgroundImage:(DKImagePicker)picker forState:(UIControlState)state;
- (void)dk_setImage:(DKImagePicker)picker forState:(UIControlState)state;
@end
//
// UIButton+Night.m
// DKNightVersion
//
// Created by Draveness on 15/12/9.
// Copyright © 2015年 DeltaX. All rights reserved.
//
#import "UIButton+Night.h"
#import <objc/runtime.h>
@interface UIButton ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, id> *pickers;
@end
@implementation UIButton (Night)
- (void)dk_setTitleColorPicker:(DKColorPicker)picker forState:(UIControlState)state {
[self setTitleColor:picker(self.dk_manager.themeVersion) forState:state];
NSString *key = [NSString stringWithFormat:@"%@", @(state)];
NSMutableDictionary *dictionary = [self.pickers valueForKey:key];
if (!dictionary) {
dictionary = [[NSMutableDictionary alloc] init];
}
[dictionary setValue:[picker copy] forKey:NSStringFromSelector(@selector(setTitleColor:forState:))];
[self.pickers setValue:dictionary forKey:key];
}
- (void)dk_setBackgroundImage:(DKImagePicker)picker forState:(UIControlState)state {
[self setBackgroundImage:picker(self.dk_manager.themeVersion) forState:state];
NSString *key = [NSString stringWithFormat:@"%@", @(state)];
NSMutableDictionary *dictionary = [self.pickers valueForKey:key];
if (!dictionary) {
dictionary = [[NSMutableDictionary alloc] init];
}
[dictionary setValue:[picker copy] forKey:NSStringFromSelector(@selector(setBackgroundImage:forState:))];
[self.pickers setValue:dictionary forKey:key];
}
- (void)dk_setImage:(DKImagePicker)picker forState:(UIControlState)state {
[self setImage:picker(self.dk_manager.themeVersion) forState:state];
NSString *key = [NSString stringWithFormat:@"%@", @(state)];
NSMutableDictionary *dictionary = [self.pickers valueForKey:key];
if (!dictionary) {
dictionary = [[NSMutableDictionary alloc] init];
}
[dictionary setValue:[picker copy] forKey:NSStringFromSelector(@selector(setImage:forState:))];
[self.pickers setValue:dictionary forKey:key];
}
- (void)night_updateColor {
[self.pickers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
if ([obj isKindOfClass:[NSDictionary class]]) {
NSDictionary<NSString *, DKColorPicker> *dictionary = (NSDictionary *)obj;
[dictionary enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull selector, DKColorPicker _Nonnull picker, BOOL * _Nonnull stop) {
UIControlState state = [key integerValue];
[UIView animateWithDuration:DKNightVersionAnimationDuration
animations:^{
if ([selector isEqualToString:NSStringFromSelector(@selector(setTitleColor:forState:))]) {
UIColor *resultColor = picker(self.dk_manager.themeVersion);
[self setTitleColor:resultColor forState:state];
} else if ([selector isEqualToString:NSStringFromSelector(@selector(setBackgroundImage:forState:))]) {
UIImage *resultImage = ((DKImagePicker)picker)(self.dk_manager.themeVersion);
[self setBackgroundImage:resultImage forState:state];
} else if ([selector isEqualToString:NSStringFromSelector(@selector(setImage:forState:))]) {
UIImage *resultImage = ((DKImagePicker)picker)(self.dk_manager.themeVersion);
[self setImage:resultImage forState:state];
}
}];
}];
} else {
SEL sel = NSSelectorFromString(key);
DKColorPicker picker = (DKColorPicker)obj;
UIColor *resultColor = picker(self.dk_manager.themeVersion);
[UIView animateWithDuration:DKNightVersionAnimationDuration
animations:^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self performSelector:sel withObject:resultColor];
#pragma clang diagnostic pop
}];
}
}];
}
@end
//
// UIImageView+Night.h
// DKNightVersion
//
// Created by Draveness on 15/12/10.
// Copyright © 2015年 DeltaX. All rights reserved.
//
#import <UIKit/UIKit.h>
#import "DKNightVersionManager.h"
NS_ASSUME_NONNULL_BEGIN
@interface UIImageView (Night)
- (instancetype)dk_initWithImagePicker:(DKImagePicker)picker;
@property (nullable, nonatomic, copy, setter = dk_setImagePicker:) DKImagePicker dk_imagePicker;
@property (nonatomic, copy, setter = dk_setAlphaPicker:) DKAlphaPicker dk_alphaPicker;
@end
NS_ASSUME_NONNULL_END
//
// UIImageView+Night.m
// DKNightVersion
//
// Created by Draveness on 15/12/10.
// Copyright © 2015年 DeltaX. All rights reserved.
//
#import "UIImageView+Night.h"
#import "NSObject+Night.h"
#import <objc/runtime.h>
#import <objc/message.h>
@interface NSObject ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, id> *pickers;
@end
@implementation UIImageView (Night)
- (instancetype)dk_initWithImagePicker:(DKImagePicker)picker {
UIImageView *imageView = [self initWithImage:picker(self.dk_manager.themeVersion)];
imageView.dk_imagePicker = [picker copy];
return imageView;
}
- (DKImagePicker)dk_imagePicker {
return objc_getAssociatedObject(self, @selector(dk_imagePicker));
}
- (void)dk_setImagePicker:(DKImagePicker)picker {
objc_setAssociatedObject(self, @selector(dk_imagePicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.image = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setImage:"];
}
- (DKAlphaPicker)dk_alphaPicker {
return objc_getAssociatedObject(self, @selector(dk_alphaPicker));
}
- (void)dk_setAlphaPicker:(DKAlphaPicker)picker {
objc_setAssociatedObject(self, @selector(dk_alphaPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.alpha = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setAlpha:"];
}
- (void)night_updateColor {
[self.pickers enumerateKeysAndObjectsUsingBlock:^(NSString * _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
if ([key isEqualToString:@"setAlpha:"]) {
DKAlphaPicker picker = (DKAlphaPicker)obj;
CGFloat alpha = picker(self.dk_manager.themeVersion);
[UIView animateWithDuration:DKNightVersionAnimationDuration
animations:^{
((void (*)(id, SEL, CGFloat))objc_msgSend)(self, NSSelectorFromString(key), alpha);
}];
} else {
SEL sel = NSSelectorFromString(key);
DKColorPicker picker = (DKColorPicker)obj;
UIColor *resultColor = picker(self.dk_manager.themeVersion);
[UIView animateWithDuration:DKNightVersionAnimationDuration
animations:^{
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[self performSelector:sel withObject:resultColor];
#pragma clang diagnostic pop
}];
}
}];
}
@end
//
// UINavigationBar+Animation.h
// DKNightVersion
//
// Created by Draveness on 15/5/4.
// Copyright (c) 2015年 DeltaX. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UINavigationBar (Animation)
- (void)animateNavigationBarToColor:(UIColor *)toColor
duration:(NSTimeInterval)duration;
@end
//
// UINavigationBar+Animation.m
// DKNightVersion
//
// Created by Draveness on 15/5/4.
// Copyright (c) 2015年 DeltaX. All rights reserved.
//
#import "UINavigationBar+Animation.h"
CGFloat const stepDuration = 0.01;
@implementation UINavigationBar (Animation)
- (void)animateNavigationBarToColor:(UIColor *)toColor duration:(NSTimeInterval)duration {
if (!self.barTintColor || !toColor) {
return;
}
UIColor *barDefaultColor = [UIColor colorWithRed:0.973 green:0.973 blue:0.973 alpha:1.0];
UIColor *barTintColor = self.barTintColor ? : barDefaultColor;
toColor = toColor ? : barDefaultColor;
NSUInteger steps = duration / stepDuration;
CGFloat fromRed, fromGreen, fromBlue, fromAlpha;
CGFloat toRed, toGreen, toBlue, toAlpha;
[barTintColor getRed:&fromRed green:&fromGreen blue:&fromBlue alpha:&fromAlpha];
[toColor getRed:&toRed green:&toGreen blue:&toBlue alpha:&toAlpha];
CGFloat diffRed = toRed - fromRed;
CGFloat diffGreen = toGreen - fromGreen;
CGFloat diffBlue = toBlue - fromBlue;
CGFloat diffAlpha = toAlpha - fromAlpha;
NSMutableArray *colorArray = [NSMutableArray array];
[colorArray addObject:barTintColor];
for (NSUInteger i = 0; i < steps - 1; ++i) {
CGFloat red = fromRed + diffRed / steps * (i + 1);
CGFloat green = fromGreen + diffGreen / steps * (i + 1);
CGFloat blue = fromBlue + diffBlue / steps * (i + 1);
CGFloat alpha = fromAlpha + diffAlpha / steps * (i + 1);
UIColor *color = [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
[colorArray addObject:color];
}
[colorArray addObject:toColor];
[self animateWithArray:colorArray];
}
- (void)animateWithArray:(NSMutableArray *)array {
NSUInteger counter = 0;
for (UIColor *color in array) {
double delayInSeconds = stepDuration * counter++;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[UIView animateWithDuration:stepDuration animations:^{
self.barTintColor = color;
}];
});
}
}
@end
//
// UISearchBar+Keyboard.h
// DKNightVersion
//
// Created by Draveness on 6/8/16.
// Copyright © 2016 Draveness. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UISearchBar (Keyboard)
@end
//
// UISearchBar+Keyboard.m
// DKNightVersion
//
// Created by Draveness on 6/8/16.
// Copyright © 2016 Draveness. All rights reserved.
//
#import "UISearchBar+Keyboard.h"
#import "NSObject+Night.h"
#import <objc/runtime.h>
@interface NSObject ()
- (void)night_updateColor;
@end
@implementation UISearchBar (Keyboard)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(init);
SEL swizzledSelector = @selector(dk_init);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod =
class_addMethod(class,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
- (instancetype)dk_init {
UISearchBar *obj = [self dk_init];
if (self.dk_manager.supportsKeyboard && [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
#ifdef __IPHONE_7_0
UITextField *searchField = [obj valueForKey:@"_searchField"];
searchField.keyboardAppearance = UIKeyboardAppearanceDark;
#else
obj.keyboardAppearance = UIKeyboardAppearanceAlert;
#endif
} else {
#ifdef __IPHONE_7_0
UITextField *searchField = [obj valueForKey:@"_searchField"];
searchField.keyboardAppearance = UIKeyboardAppearanceDefault;
#else
obj.keyboardAppearance = UIKeyboardAppearanceDefault;
#endif
}
return obj;
}
- (void)night_updateColor {
[super night_updateColor];
if (self.dk_manager.supportsKeyboard && [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
#ifdef __IPHONE_7_0
UITextField *searchField = [self valueForKey:@"_searchField"];
searchField.keyboardAppearance = UIKeyboardAppearanceDark;
#else
self.keyboardAppearance = UIKeyboardAppearanceAlert;
#endif
} else {
#ifdef __IPHONE_7_0
UITextField *searchField = [self valueForKey:@"_searchField"];
searchField.keyboardAppearance = UIKeyboardAppearanceDefault;
#else
self.keyboardAppearance = UIKeyboardAppearanceDefault;
#endif
}
}
@end
//
// UITextField+Keyboard.h
// DKNightVersion
//
// Created by Draveness on 16/4/11.
// Copyright © 2016年 Draveness. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UITextField (Keyboard)
@end
//
// UITextField+Keyboard.m
// DKNightVersion
//
// Created by Draveness on 16/4/11.
// Copyright © 2016年 Draveness. All rights reserved.
//
#import "UITextField+Keyboard.h"
#import "NSObject+Night.h"
#import <objc/runtime.h>
@interface NSObject ()
- (void)night_updateColor;
@end
@implementation UITextField (Keyboard)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(init);
SEL swizzledSelector = @selector(dk_init);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod =
class_addMethod(class,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
- (instancetype)dk_init {
UITextField *obj = [self dk_init];
if (self.dk_manager.supportsKeyboard && [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
#ifdef __IPHONE_7_0
obj.keyboardAppearance = UIKeyboardAppearanceDark;
#else
obj.keyboardAppearance = UIKeyboardAppearanceAlert;
#endif
} else {
obj.keyboardAppearance = UIKeyboardAppearanceDefault;
}
return obj;
}
- (void)night_updateColor {
[super night_updateColor];
if (self.dk_manager.supportsKeyboard && [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
#ifdef __IPHONE_7_0
self.keyboardAppearance = UIKeyboardAppearanceDark;
#else
self.keyboardAppearance = UIKeyboardAppearanceAlert;
#endif
} else {
self.keyboardAppearance = UIKeyboardAppearanceDefault;
}
}
@end
//
// UITextView+Keyboard.h
// DKNightVersion
//
// Created by Draveness on 6/5/16.
// Copyright © 2016 Draveness. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UITextView (Keyboard)
@end
//
// UITextView+Keyboard.m
// DKNightVersion
//
// Created by Draveness on 6/5/16.
// Copyright © 2016 Draveness. All rights reserved.
//
#import "UITextView+Keyboard.h"
#import "NSObject+Night.h"
#import <objc/runtime.h>
@interface NSObject ()
- (void)night_updateColor;
@end
@implementation UITextView (Keyboard)
+ (void)load {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
Class class = [self class];
SEL originalSelector = @selector(init);
SEL swizzledSelector = @selector(dk_init);
Method originalMethod = class_getInstanceMethod(class, originalSelector);
Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector);
BOOL didAddMethod =
class_addMethod(class,
originalSelector,
method_getImplementation(swizzledMethod),
method_getTypeEncoding(swizzledMethod));
if (didAddMethod) {
class_replaceMethod(class,
swizzledSelector,
method_getImplementation(originalMethod),
method_getTypeEncoding(originalMethod));
} else {
method_exchangeImplementations(originalMethod, swizzledMethod);
}
});
}
- (instancetype)dk_init {
UITextView *obj = [self dk_init];
if (self.dk_manager.supportsKeyboard && [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
#ifdef __IPHONE_7_0
obj.keyboardAppearance = UIKeyboardAppearanceDark;
#else
obj.keyboardAppearance = UIKeyboardAppearanceAlert;
#endif
} else {
obj.keyboardAppearance = UIKeyboardAppearanceDefault;
}
return obj;
}
- (void)night_updateColor {
[super night_updateColor];
if (self.dk_manager.supportsKeyboard && [self.dk_manager.themeVersion isEqualToString:DKThemeVersionNight]) {
#ifdef __IPHONE_7_0
self.keyboardAppearance = UIKeyboardAppearanceDark;
#else
self.keyboardAppearance = UIKeyboardAppearanceAlert;
#endif
} else {
self.keyboardAppearance = UIKeyboardAppearanceDefault;
}
}
@end
//
// UIBarButtonItem+Night.h
// UIBarButtonItem+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UIBarButtonItem (Night)
@property (nonatomic, copy, setter = dk_setTintColorPicker:) DKColorPicker dk_tintColorPicker;
@end
//
// UIBarButtonItem+Night.m
// UIBarButtonItem+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UIBarButtonItem+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UIBarButtonItem ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UIBarButtonItem (Night)
- (DKColorPicker)dk_tintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_tintColorPicker));
}
- (void)dk_setTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_tintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.tintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setTintColor:"];
}
@end
//
// UIControl+Night.h
// UIControl+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UIControl (Night)
@property (nonatomic, copy, setter = dk_setTintColorPicker:) DKColorPicker dk_tintColorPicker;
@end
//
// UIControl+Night.m
// UIControl+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UIControl+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UIControl ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UIControl (Night)
- (DKColorPicker)dk_tintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_tintColorPicker));
}
- (void)dk_setTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_tintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.tintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setTintColor:"];
}
@end
//
// UILabel+Night.h
// UILabel+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UILabel (Night)
@property (nonatomic, copy, setter = dk_setTextColorPicker:) DKColorPicker dk_textColorPicker;
@property (nonatomic, copy, setter = dk_setShadowColorPicker:) DKColorPicker dk_shadowColorPicker;
@property (nonatomic, copy, setter = dk_setHighlightedTextColorPicker:) DKColorPicker dk_highlightedTextColorPicker;
@end
//
// UILabel+Night.m
// UILabel+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UILabel+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UILabel ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UILabel (Night)
- (DKColorPicker)dk_textColorPicker {
return objc_getAssociatedObject(self, @selector(dk_textColorPicker));
}
- (void)dk_setTextColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_textColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.textColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setTextColor:"];
}
- (DKColorPicker)dk_shadowColorPicker {
return objc_getAssociatedObject(self, @selector(dk_shadowColorPicker));
}
- (void)dk_setShadowColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_shadowColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.shadowColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setShadowColor:"];
}
- (DKColorPicker)dk_highlightedTextColorPicker {
return objc_getAssociatedObject(self, @selector(dk_highlightedTextColorPicker));
}
- (void)dk_setHighlightedTextColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_highlightedTextColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.highlightedTextColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setHighlightedTextColor:"];
}
@end
//
// UINavigationBar+Night.h
// UINavigationBar+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UINavigationBar (Night)
@property (nonatomic, copy, setter = dk_setBarTintColorPicker:) DKColorPicker dk_barTintColorPicker;
@property (nonatomic, copy, setter = dk_setTintColorPicker:) DKColorPicker dk_tintColorPicker;
@end
//
// UINavigationBar+Night.m
// UINavigationBar+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UINavigationBar+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UINavigationBar ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UINavigationBar (Night)
- (DKColorPicker)dk_barTintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_barTintColorPicker));
}
- (void)dk_setBarTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_barTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.barTintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setBarTintColor:"];
}
- (DKColorPicker)dk_tintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_tintColorPicker));
}
- (void)dk_setTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_tintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.tintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setTintColor:"];
}
@end
//
// UIPageControl+Night.h
// UIPageControl+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UIPageControl (Night)
@property (nonatomic, copy, setter = dk_setPageIndicatorTintColorPicker:) DKColorPicker dk_pageIndicatorTintColorPicker;
@property (nonatomic, copy, setter = dk_setCurrentPageIndicatorTintColorPicker:) DKColorPicker dk_currentPageIndicatorTintColorPicker;
@end
//
// UIPageControl+Night.m
// UIPageControl+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UIPageControl+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UIPageControl ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UIPageControl (Night)
- (DKColorPicker)dk_pageIndicatorTintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_pageIndicatorTintColorPicker));
}
- (void)dk_setPageIndicatorTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_pageIndicatorTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.pageIndicatorTintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setPageIndicatorTintColor:"];
}
- (DKColorPicker)dk_currentPageIndicatorTintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_currentPageIndicatorTintColorPicker));
}
- (void)dk_setCurrentPageIndicatorTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_currentPageIndicatorTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.currentPageIndicatorTintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setCurrentPageIndicatorTintColor:"];
}
@end
//
// UIProgressView+Night.h
// UIProgressView+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UIProgressView (Night)
@property (nonatomic, copy, setter = dk_setProgressTintColorPicker:) DKColorPicker dk_progressTintColorPicker;
@property (nonatomic, copy, setter = dk_setTrackTintColorPicker:) DKColorPicker dk_trackTintColorPicker;
@end
//
// UIProgressView+Night.m
// UIProgressView+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UIProgressView+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UIProgressView ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UIProgressView (Night)
- (DKColorPicker)dk_progressTintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_progressTintColorPicker));
}
- (void)dk_setProgressTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_progressTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.progressTintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setProgressTintColor:"];
}
- (DKColorPicker)dk_trackTintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_trackTintColorPicker));
}
- (void)dk_setTrackTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_trackTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.trackTintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setTrackTintColor:"];
}
@end
//
// UISearchBar+Night.h
// UISearchBar+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UISearchBar (Night)
@property (nonatomic, copy, setter = dk_setBarTintColorPicker:) DKColorPicker dk_barTintColorPicker;
@end
//
// UISearchBar+Night.m
// UISearchBar+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UISearchBar+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UISearchBar ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UISearchBar (Night)
- (DKColorPicker)dk_barTintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_barTintColorPicker));
}
- (void)dk_setBarTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_barTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.barTintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setBarTintColor:"];
}
@end
//
// UISlider+Night.h
// UISlider+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UISlider (Night)
@property (nonatomic, copy, setter = dk_setMinimumTrackTintColorPicker:) DKColorPicker dk_minimumTrackTintColorPicker;
@property (nonatomic, copy, setter = dk_setMaximumTrackTintColorPicker:) DKColorPicker dk_maximumTrackTintColorPicker;
@property (nonatomic, copy, setter = dk_setThumbTintColorPicker:) DKColorPicker dk_thumbTintColorPicker;
@end
//
// UISlider+Night.m
// UISlider+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UISlider+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UISlider ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UISlider (Night)
- (DKColorPicker)dk_minimumTrackTintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_minimumTrackTintColorPicker));
}
- (void)dk_setMinimumTrackTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_minimumTrackTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.minimumTrackTintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setMinimumTrackTintColor:"];
}
- (DKColorPicker)dk_maximumTrackTintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_maximumTrackTintColorPicker));
}
- (void)dk_setMaximumTrackTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_maximumTrackTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.maximumTrackTintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setMaximumTrackTintColor:"];
}
- (DKColorPicker)dk_thumbTintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_thumbTintColorPicker));
}
- (void)dk_setThumbTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_thumbTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.thumbTintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setThumbTintColor:"];
}
@end
//
// UISwitch+Night.h
// UISwitch+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UISwitch (Night)
@property (nonatomic, copy, setter = dk_setOnTintColorPicker:) DKColorPicker dk_onTintColorPicker;
@property (nonatomic, copy, setter = dk_setThumbTintColorPicker:) DKColorPicker dk_thumbTintColorPicker;
@end
//
// UISwitch+Night.m
// UISwitch+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UISwitch+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UISwitch ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UISwitch (Night)
- (DKColorPicker)dk_onTintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_onTintColorPicker));
}
- (void)dk_setOnTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_onTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.onTintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setOnTintColor:"];
}
- (DKColorPicker)dk_thumbTintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_thumbTintColorPicker));
}
- (void)dk_setThumbTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_thumbTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.thumbTintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setThumbTintColor:"];
}
@end
//
// UITabBar+Night.h
// UITabBar+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UITabBar (Night)
@property (nonatomic, copy, setter = dk_setBarTintColorPicker:) DKColorPicker dk_barTintColorPicker;
@end
//
// UITabBar+Night.m
// UITabBar+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UITabBar+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UITabBar ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UITabBar (Night)
- (DKColorPicker)dk_barTintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_barTintColorPicker));
}
- (void)dk_setBarTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_barTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.barTintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setBarTintColor:"];
}
@end
//
// UITableView+Night.h
// UITableView+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UITableView (Night)
@property (nonatomic, copy, setter = dk_setSeparatorColorPicker:) DKColorPicker dk_separatorColorPicker;
@property (nonatomic, copy, setter = dk_setSectionIndexColorPicker:) DKColorPicker dk_sectionIndexColorPicker;
@property (nonatomic, copy, setter = dk_setSectionIndexBackgroundColorPicker:) DKColorPicker dk_sectionIndexBackgroundColorPicker;
@property (nonatomic, copy, setter = dk_setSectionIndexTrackingBackgroundColorPicker:) DKColorPicker dk_sectionIndexTrackingBackgroundColorPicker;
@end
//
// UITableView+Night.m
// UITableView+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UITableView+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UITableView ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UITableView (Night)
- (DKColorPicker)dk_separatorColorPicker {
return objc_getAssociatedObject(self, @selector(dk_separatorColorPicker));
}
- (void)dk_setSeparatorColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_separatorColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.separatorColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setSeparatorColor:"];
}
- (DKColorPicker)dk_sectionIndexColorPicker {
return objc_getAssociatedObject(self, @selector(dk_sectionIndexColorPicker));
}
- (void)dk_setSectionIndexColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_sectionIndexColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.sectionIndexColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setSectionIndexColor:"];
}
- (DKColorPicker)dk_sectionIndexBackgroundColorPicker {
return objc_getAssociatedObject(self, @selector(dk_sectionIndexBackgroundColorPicker));
}
- (void)dk_setSectionIndexBackgroundColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_sectionIndexBackgroundColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.sectionIndexBackgroundColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setSectionIndexBackgroundColor:"];
}
- (DKColorPicker)dk_sectionIndexTrackingBackgroundColorPicker {
return objc_getAssociatedObject(self, @selector(dk_sectionIndexTrackingBackgroundColorPicker));
}
- (void)dk_setSectionIndexTrackingBackgroundColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_sectionIndexTrackingBackgroundColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.sectionIndexTrackingBackgroundColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setSectionIndexTrackingBackgroundColor:"];
}
@end
//
// UITextField+Night.h
// UITextField+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UITextField (Night)
@property (nonatomic, copy, setter = dk_setTextColorPicker:) DKColorPicker dk_textColorPicker;
@end
//
// UITextField+Night.m
// UITextField+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UITextField+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UITextField ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UITextField (Night)
- (DKColorPicker)dk_textColorPicker {
return objc_getAssociatedObject(self, @selector(dk_textColorPicker));
}
- (void)dk_setTextColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_textColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.textColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setTextColor:"];
}
@end
//
// UITextView+Night.h
// UITextView+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UITextView (Night)
@property (nonatomic, copy, setter = dk_setTextColorPicker:) DKColorPicker dk_textColorPicker;
@end
//
// UITextView+Night.m
// UITextView+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UITextView+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UITextView ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UITextView (Night)
- (DKColorPicker)dk_textColorPicker {
return objc_getAssociatedObject(self, @selector(dk_textColorPicker));
}
- (void)dk_setTextColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_textColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.textColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setTextColor:"];
}
@end
//
// UIToolbar+Night.h
// UIToolbar+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UIToolbar (Night)
@property (nonatomic, copy, setter = dk_setBarTintColorPicker:) DKColorPicker dk_barTintColorPicker;
@end
//
// UIToolbar+Night.m
// UIToolbar+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UIToolbar+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UIToolbar ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UIToolbar (Night)
- (DKColorPicker)dk_barTintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_barTintColorPicker));
}
- (void)dk_setBarTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_barTintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.barTintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setBarTintColor:"];
}
@end
//
// UIView+Night.h
// UIView+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import <UIKit/UIKit.h>
#import "NSObject+Night.h"
@interface UIView (Night)
@property (nonatomic, copy, setter = dk_setBackgroundColorPicker:) DKColorPicker dk_backgroundColorPicker;
@property (nonatomic, copy, setter = dk_setTintColorPicker:) DKColorPicker dk_tintColorPicker;
@end
//
// UIView+Night.m
// UIView+Night
//
// Copyright (c) 2015 Draveness. All rights reserved.
//
// These files are generated by ruby script, if you want to modify code
// in this file, you are supposed to update the ruby code, run it and
// test it. And finally open a pull request.
#import "UIView+Night.h"
#import "DKNightVersionManager.h"
#import <objc/runtime.h>
@interface UIView ()
@property (nonatomic, strong) NSMutableDictionary<NSString *, DKColorPicker> *pickers;
@end
@implementation UIView (Night)
- (DKColorPicker)dk_backgroundColorPicker {
return objc_getAssociatedObject(self, @selector(dk_backgroundColorPicker));
}
- (void)dk_setBackgroundColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_backgroundColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.backgroundColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setBackgroundColor:"];
}
- (DKColorPicker)dk_tintColorPicker {
return objc_getAssociatedObject(self, @selector(dk_tintColorPicker));
}
- (void)dk_setTintColorPicker:(DKColorPicker)picker {
objc_setAssociatedObject(self, @selector(dk_tintColorPicker), picker, OBJC_ASSOCIATION_COPY_NONATOMIC);
self.tintColor = picker(self.dk_manager.themeVersion);
[self.pickers setValue:[picker copy] forKey:@"setTintColor:"];
}
@end
//
// EXTKeyPathCoding.h
// extobjc
//
// Created by Justin Spahr-Summers on 19.06.12.
// Copyright (C) 2012 Justin Spahr-Summers.
// Released under the MIT license.
//
#import <Foundation/Foundation.h>
#import "metamacros.h"
/**
* \@keypath allows compile-time verification of key paths. Given a real object
* receiver and key path:
*
* @code
NSString *UTF8StringPath = @keypath(str.lowercaseString.UTF8String);
// => @"lowercaseString.UTF8String"
NSString *versionPath = @keypath(NSObject, version);
// => @"version"
NSString *lowercaseStringPath = @keypath(NSString.new, lowercaseString);
// => @"lowercaseString"
* @endcode
*
* ... the macro returns an \c NSString containing all but the first path
* component or argument (e.g., @"lowercaseString.UTF8String", @"version").
*
* In addition to simply creating a key path, this macro ensures that the key
* path is valid at compile-time (causing a syntax error if not), and supports
* refactoring, such that changing the name of the property will also update any
* uses of \@keypath.
*/
#define keypath(...) \
metamacro_if_eq(1, metamacro_argcount(__VA_ARGS__))(keypath1(__VA_ARGS__))(keypath2(__VA_ARGS__))
#define keypath1(PATH) \
(((void)(NO && ((void)PATH, NO)), strchr(# PATH, '.') + 1))
#define keypath2(OBJ, PATH) \
(((void)(NO && ((void)OBJ.PATH, NO)), # PATH))
/**
* \@collectionKeypath allows compile-time verification of key paths across collections NSArray/NSSet etc. Given a real object
* receiver, collection object receiver and related keypaths:
*
* @code
NSString *employessFirstNamePath = @collectionKeypath(department.employees, Employee.new, firstName)
// => @"employees.firstName"
NSString *employessFirstNamePath = @collectionKeypath(Department.new, employees, Employee.new, firstName)
// => @"employees.firstName"
* @endcode
*
*/
#define collectionKeypath(...) \
metamacro_if_eq(3, metamacro_argcount(__VA_ARGS__))(collectionKeypath3(__VA_ARGS__))(collectionKeypath4(__VA_ARGS__))
#define collectionKeypath3(PATH, COLLECTION_OBJECT, COLLECTION_PATH) ([[NSString stringWithFormat:@"%s.%s",keypath(PATH), keypath(COLLECTION_OBJECT, COLLECTION_PATH)] UTF8String])
#define collectionKeypath4(OBJ, PATH, COLLECTION_OBJECT, COLLECTION_PATH) ([[NSString stringWithFormat:@"%s.%s",keypath(OBJ, PATH), keypath(COLLECTION_OBJECT, COLLECTION_PATH)] UTF8String])
The MIT License (MIT)
Copyright (c) 2015 Draveness
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
PODS:
- AFNetworking/NSURLSession (4.0.1):
- AFNetworking/Reachability
- AFNetworking/Security
- AFNetworking/Serialization
- AFNetworking/Reachability (4.0.1)
- AFNetworking/Security (4.0.1)
- AFNetworking/Serialization (4.0.1)
- DKNightVersion (2.4.3):
- DKNightVersion/Core (= 2.4.3)
- DKNightVersion/CoreAnimation (= 2.4.3)
- DKNightVersion/UIKit (= 2.4.3)
- DKNightVersion/Core (2.4.3):
- DKNightVersion/Core/DeallocBlockExecutor (= 2.4.3)
- DKNightVersion/Core/extobjc (= 2.4.3)
- DKNightVersion/Core/DeallocBlockExecutor (2.4.3)
- DKNightVersion/Core/extobjc (2.4.3)
- DKNightVersion/CoreAnimation (2.4.3):
- DKNightVersion/Core
- DKNightVersion/UIKit (2.4.3):
- DKNightVersion/Core
- YTKNetwork (3.0.6):
- AFNetworking/NSURLSession (~> 4.0)
DEPENDENCIES:
- DKNightVersion (~> 2.4.3)
- YTKNetwork (~> 3.0.6)
SPEC REPOS:
trunk:
- AFNetworking
- DKNightVersion
- YTKNetwork
SPEC CHECKSUMS:
AFNetworking: 7864c38297c79aaca1500c33288e429c3451fdce
DKNightVersion: eaa80cc4014b4bae7d4b535fd87ecc6a3c2767b3
YTKNetwork: c16be90b06be003de9e9cd0d3b187cc8eaf35c04
PODFILE CHECKSUM: f640463a1ebbe4ec2fcd53457d010319e70f41db
COCOAPODS: 1.11.3
此文件的差异太大,无法显示。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>4.0.1</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${CURRENT_PROJECT_VERSION}</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
#import <Foundation/Foundation.h>
@interface PodsDummy_AFNetworking : NSObject
@end
@implementation PodsDummy_AFNetworking
@end
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
#import "AFHTTPSessionManager.h"
#import "AFURLSessionManager.h"
#import "AFCompatibilityMacros.h"
#import "AFNetworkReachabilityManager.h"
#import "AFSecurityPolicy.h"
#import "AFURLRequestSerialization.h"
#import "AFURLResponseSerialization.h"
FOUNDATION_EXPORT double AFNetworkingVersionNumber;
FOUNDATION_EXPORT const unsigned char AFNetworkingVersionString[];
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO
CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_ROOT = ${SRCROOT}
PODS_TARGET_SRCROOT = ${PODS_ROOT}/AFNetworking
PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates
PRODUCT_BUNDLE_IDENTIFIER = com.alamofire.AFNetworking
SKIP_INSTALL = YES
USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES
framework module AFNetworking {
umbrella header "AFNetworking-umbrella.h"
export *
module * { export * }
}
CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = NO
CONFIGURATION_BUILD_DIR = ${PODS_CONFIGURATION_BUILD_DIR}/AFNetworking
GCC_PREPROCESSOR_DEFINITIONS = $(inherited) COCOAPODS=1
PODS_BUILD_DIR = ${BUILD_DIR}
PODS_CONFIGURATION_BUILD_DIR = ${PODS_BUILD_DIR}/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)
PODS_ROOT = ${SRCROOT}
PODS_TARGET_SRCROOT = ${PODS_ROOT}/AFNetworking
PODS_XCFRAMEWORKS_BUILD_DIR = $(PODS_CONFIGURATION_BUILD_DIR)/XCFrameworkIntermediates
PRODUCT_BUNDLE_IDENTIFIER = com.alamofire.AFNetworking
SKIP_INSTALL = YES
USE_RECURSIVE_SCRIPT_INPUTS_IN_SCRIPT_PHASES = YES
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>${PRODUCT_BUNDLE_IDENTIFIER}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>2.4.3</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>${CURRENT_PROJECT_VERSION}</string>
<key>NSPrincipalClass</key>
<string></string>
</dict>
</plist>
#import <Foundation/Foundation.h>
@interface PodsDummy_DKNightVersion : NSObject
@end
@implementation PodsDummy_DKNightVersion
@end
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
#import "DKNightVersion.h"
#import "DKAlpha.h"
#import "DKColor.h"
#import "DKImage.h"
#import "DKNightVersionManager.h"
#import "NSObject+Night.h"
#import "DKColorTable.h"
#import "DKDeallocBlockExecutor.h"
#import "NSObject+DeallocBlock.h"
#import "EXTKeyPathCoding.h"
#import "metamacros.h"
#import "CALayer+Night.h"
#import "CAShapeLayer+Night.h"
#import "CoreAnimation+Night.h"
#import "UIBarButtonItem+Night.h"
#import "UIControl+Night.h"
#import "UILabel+Night.h"
#import "UINavigationBar+Night.h"
#import "UIPageControl+Night.h"
#import "UIProgressView+Night.h"
#import "UISearchBar+Night.h"
#import "UISlider+Night.h"
#import "UISwitch+Night.h"
#import "UITabBar+Night.h"
#import "UITableView+Night.h"
#import "UITextField+Night.h"
#import "UITextView+Night.h"
#import "UIToolbar+Night.h"
#import "UIView+Night.h"
#import "UIButton+Night.h"
#import "UIImageView+Night.h"
#import "UINavigationBar+Animation.h"
#import "UISearchBar+Keyboard.h"
#import "UITextField+Keyboard.h"
#import "UITextView+Keyboard.h"
FOUNDATION_EXPORT double DKNightVersionVersionNumber;
FOUNDATION_EXPORT const unsigned char DKNightVersionVersionString[];
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!