├── DMAppearance.podspec ├── DMAppearance ├── DMAppearance.h ├── DMAppearanceRecorder.h └── DMAppearanceRecorder.m ├── Demo ├── DMAppearance.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ └── contents.xcworkspacedata ├── Resources │ ├── Base.lproj │ │ ├── LaunchScreen.xib │ │ └── Main.storyboard │ ├── Default-568h@2x.png │ ├── Images.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ └── Info.plist └── Sources │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── DMView.h │ ├── DMView.m │ ├── Model │ ├── DMObjectsRenderer.h │ ├── DMObjectsRenderer.m │ ├── DMUIElipse.h │ ├── DMUIElipse.m │ ├── DMUIObject.h │ ├── DMUIObject.m │ ├── DMUISquare.h │ └── DMUISquare.m │ ├── ViewController.h │ ├── ViewController.m │ └── main.m ├── LICENSE.md └── README.md /DMAppearance.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "DMAppearance" 3 | s.version = "0.1.1" 4 | s.summary = "Partial functionality from UIAppearance proxy for custom objects" 5 | s.description = <<-DESC 6 | * Partial functionality from UIAppearance proxy for custom objects apart from UIKit ones 7 | DESC 8 | s.homepage = "https://github.com/andrewgubanov/DMAppearance" 9 | s.license = { 10 | :type => 'MIT', 11 | :file => 'LICENSE.md' 12 | } 13 | s.author = { "AG" => "andrew.gubanov@icloud.com" } 14 | s.platform = :ios, '7.0' 15 | s.source = { 16 | :git => 'https://github.com/andrewgubanov/DMAppearance.git', 17 | :tag => s.version.to_s 18 | } 19 | s.source_files = 'DMAppearance/*.{h,m}' 20 | s.frameworks = 'Foundation', 'CoreGraphics' 21 | s.requires_arc = true 22 | end 23 | -------------------------------------------------------------------------------- /DMAppearance/DMAppearance.h: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // DMAppearance.h 4 | // DMAppearance 5 | // 6 | // Created by Andrew Gubanov on 19/02/15. 7 | // Copyright 2015 Andrew Gubanov. All rights reserved. 8 | // 9 | // 10 | 11 | @import Foundation; 12 | 13 | /* 14 | Appearance property selectors must be of the form: 15 | - (void)setProperty:(PropertyType)property forAxis1:(PropertyType)axis1 axis2:(PropertyType)axis2 axisN:(PropertyType)axisN; 16 | - (PropertyType)propertyForAxis1:(PropertyType)axis1 axis2:(PropertyType)axis2 axisN:(PropertyType)axisN; 17 | You may have no axes or as many as you like for any property. PropertyType may be any standard iOS type: id, BOOL NSInteger, NSUInteger, CGFloat, CGPoint, CGSize, CGRect. Exception will be thrown if any other type is met. 18 | */ 19 | 20 | @protocol DMAppearance 21 | + (instancetype)appearance; 22 | @end 23 | -------------------------------------------------------------------------------- /DMAppearance/DMAppearanceRecorder.h: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // DMAppearanceRecorder.h 4 | // DMAppearance 5 | // 6 | // Created by Andrew Gubanov on 19/02/15. 7 | // Copyright 2015 Andrew Gubanov. All rights reserved. 8 | // 9 | // 10 | 11 | @import Foundation; 12 | 13 | @interface DMAppearanceRecorder : NSProxy 14 | + (instancetype)appearanceRecorderForClass:(Class)aClass; 15 | - (void)applyAppearanceForTarget:(id)aTarget; 16 | @end 17 | -------------------------------------------------------------------------------- /DMAppearance/DMAppearanceRecorder.m: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // DMAppearanceRecorder.m 4 | // DMAppearance 5 | // 6 | // Created by Andrew Gubanov on 19/02/15. 7 | // Copyright 2015 Andrew Gubanov. All rights reserved. 8 | // 9 | // 10 | 11 | @import CoreGraphics; 12 | #import "DMAppearanceRecorder.h" 13 | #import 14 | 15 | static NSMutableDictionary *sDMClassRecorders = nil; 16 | 17 | static void* DMReplacementMethod(id self, SEL _cmd, ...); 18 | static void fillInvocationWithArguments(NSInvocation *anInvocation, va_list anArguments, NSMethodSignature *aMethodSignature); 19 | typedef void (^DMDecodingBlock)(NSInvocation *anInvocation, va_list anArguments, NSInteger anIndex); 20 | 21 | 22 | @interface NSString (DMAppearanceRecorderEncoding) 23 | - (BOOL)dm_hasCaseInsensitivePrefix:(NSString *)aPrefix; 24 | - (NSString *)dm_stringByRemovingEnodingQualifiers; 25 | @end 26 | 27 | @implementation NSString (Encoding) 28 | 29 | - (BOOL)dm_hasCaseInsensitivePrefix:(NSString *)aPrefix 30 | { 31 | NSString *token = [aPrefix uppercaseString]; 32 | NSString *sorce = [self uppercaseString]; 33 | return [sorce hasPrefix:token]; 34 | } 35 | 36 | - (NSString *)dm_stringByRemovingEnodingQualifiers 37 | { 38 | if ( ([self dm_hasCaseInsensitivePrefix:@"n"]) || 39 | ([self dm_hasCaseInsensitivePrefix:@"o"]) || 40 | ([self dm_hasCaseInsensitivePrefix:@"r"]) || 41 | ([self hasPrefix:@"V"]) ) { 42 | return [self substringFromIndex:1]; 43 | } else { 44 | return self; 45 | } 46 | } 47 | @end 48 | 49 | 50 | @interface DMAppearanceRecorder () 51 | @property (atomic, strong) Class targetClass; 52 | @property (atomic, strong) NSMutableDictionary *originalIMPs; 53 | @property (atomic, strong) NSMutableDictionary *invocations; 54 | @property (atomic, strong) NSMutableDictionary *calledOriginals; 55 | @end 56 | 57 | @implementation DMAppearanceRecorder 58 | 59 | + (instancetype)appearanceRecorderForClass:(Class)aClass 60 | { 61 | DMAppearanceRecorder *result = nil; 62 | @synchronized (self) { 63 | 64 | static dispatch_once_t onceToken; 65 | dispatch_once(&onceToken, ^{ 66 | sDMClassRecorders = [[NSMutableDictionary alloc] init]; 67 | }); 68 | 69 | NSString *key = NSStringFromClass(aClass); 70 | if (key != nil) { 71 | result = sDMClassRecorders[key]; 72 | if (result == nil) { 73 | result = [[self alloc] init]; 74 | result.targetClass = aClass; 75 | sDMClassRecorders[key] = result; 76 | } 77 | } 78 | } 79 | return result; 80 | } 81 | 82 | - (instancetype)init 83 | { 84 | self.invocations = [NSMutableDictionary dictionary]; 85 | self.calledOriginals = [NSMutableDictionary dictionary]; 86 | self.originalIMPs = [NSMutableDictionary dictionary]; 87 | return self; 88 | } 89 | 90 | - (void)applyAppearanceForTarget:(id)aTarget 91 | { 92 | NSArray *canceledRecords = nil; 93 | @synchronized (self.calledOriginals) { 94 | NSValue *key = [NSValue valueWithNonretainedObject:aTarget]; 95 | canceledRecords = self.calledOriginals[key]; 96 | } 97 | NSDictionary *invocations = nil; 98 | @synchronized (self.invocations) { 99 | invocations = self.invocations; 100 | } 101 | [invocations enumerateKeysAndObjectsUsingBlock:^(id aKey, id anObj, BOOL *stop) { 102 | //aKey = selector, anObj = NSInvocation 103 | if (![canceledRecords containsObject:aKey]) { 104 | 105 | NSInvocation *invocation = anObj; 106 | IMP originalIMP = NULL; 107 | @synchronized (self.originalIMPs) { 108 | originalIMP = [self.originalIMPs[NSStringFromSelector(invocation.selector)] pointerValue]; 109 | } 110 | //swizzle back to original imp, so it could be correctly handleled in [invocation invoke]; 111 | Method method = class_getInstanceMethod([aTarget class], invocation.selector); 112 | method_setImplementation(method, originalIMP); 113 | 114 | [invocation setTarget:aTarget]; 115 | [invocation invoke]; 116 | [invocation setTarget:nil]; 117 | 118 | //swizzle back as we still want to keep track of any mehod custom calls 119 | method_setImplementation(method, (IMP)DMReplacementMethod); 120 | } 121 | }]; 122 | } 123 | 124 | - (void)forwardInvocation:(NSInvocation *)anInvocation 125 | { 126 | @synchronized (self.invocations) { 127 | NSString *key = NSStringFromSelector(anInvocation.selector); 128 | if (key != nil) { 129 | if (self.invocations[key] == nil) { 130 | Method method = class_getInstanceMethod(self.targetClass, anInvocation.selector); 131 | IMP originalIMP = method_setImplementation(method, (IMP)DMReplacementMethod); 132 | @synchronized (self.originalIMPs) { 133 | self.originalIMPs[key] = [NSValue valueWithPointer:originalIMP]; 134 | } 135 | } 136 | [anInvocation setTarget:nil]; 137 | [anInvocation retainArguments]; 138 | self.invocations[key] = anInvocation; 139 | } 140 | } 141 | } 142 | 143 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector 144 | { 145 | NSMethodSignature *result = nil; 146 | if (self.targetClass != nil) { 147 | result = [self.targetClass instanceMethodSignatureForSelector:aSelector]; 148 | } else { 149 | result = [super methodSignatureForSelector:aSelector]; 150 | } 151 | return result; 152 | } 153 | @end 154 | 155 | static void* DMReplacementMethod(id self, SEL _cmd, ...) 156 | { 157 | IMP originalIMP = NULL; 158 | DMAppearanceRecorder *recorder = [DMAppearanceRecorder appearanceRecorderForClass:[self class]]; 159 | @synchronized (recorder.originalIMPs) { 160 | originalIMP = [recorder.originalIMPs[NSStringFromSelector(_cmd)] pointerValue]; 161 | } 162 | @synchronized (recorder.calledOriginals) { 163 | NSValue *key = [NSValue valueWithNonretainedObject:self]; 164 | NSMutableArray *records = recorder.calledOriginals[key]; 165 | if (records == nil) { 166 | records = [NSMutableArray array]; 167 | recorder.calledOriginals[key] = records; 168 | } 169 | NSString *record = NSStringFromSelector(_cmd); 170 | if (![records containsObject:record]) { 171 | [records addObject:record]; 172 | } 173 | } 174 | //swizzle back to original imp, so it could be correctly handleled in [invocation invoke]; 175 | Method method = class_getInstanceMethod([self class], _cmd); 176 | method_setImplementation(method, originalIMP); 177 | 178 | NSMethodSignature *methodSignature = [self methodSignatureForSelector:_cmd]; 179 | NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature]; 180 | invocation.selector = _cmd; 181 | invocation.target = self; 182 | 183 | va_list arguments; 184 | va_start(arguments, _cmd); 185 | fillInvocationWithArguments(invocation, arguments, methodSignature); 186 | va_end(arguments); 187 | 188 | [invocation invoke]; 189 | 190 | //swizzle back as we still want to keep track of any mehod custom calls 191 | method_setImplementation(method, (IMP)DMReplacementMethod); 192 | 193 | void *returnValue = nil; 194 | if (methodSignature.methodReturnLength != 0) { 195 | [invocation getReturnValue:&returnValue]; 196 | } 197 | return returnValue; 198 | } 199 | 200 | static void fillInvocationWithArguments(NSInvocation *anInvocation, va_list anArguments, NSMethodSignature *aMethodSignature) 201 | { 202 | static dispatch_once_t onceToken; 203 | static NSMutableDictionary *sDMArgumentsDecoder = nil; 204 | dispatch_once(&onceToken, ^{ 205 | sDMArgumentsDecoder = [[NSMutableDictionary alloc] init]; 206 | 207 | DMDecodingBlock decodingBlock = ^(NSInvocation *anInvocation, va_list anArguments, NSInteger anIndex) { 208 | id token = va_arg(anArguments, id); 209 | [anInvocation setArgument:&token atIndex:anIndex]; 210 | }; 211 | sDMArgumentsDecoder[@"@"] = decodingBlock; 212 | 213 | decodingBlock = ^(NSInvocation *anInvocation, va_list anArguments, NSInteger anIndex) { 214 | BOOL token = va_arg(anArguments, int); 215 | [anInvocation setArgument:&token atIndex:anIndex]; 216 | }; 217 | NSString *key = [[[NSString stringWithUTF8String:@encode(BOOL)] dm_stringByRemovingEnodingQualifiers] uppercaseString]; 218 | sDMArgumentsDecoder[key] = decodingBlock; 219 | 220 | decodingBlock = ^(NSInvocation *anInvocation, va_list anArguments, NSInteger anIndex) { 221 | NSInteger token = va_arg(anArguments, NSInteger); 222 | [anInvocation setArgument:&token atIndex:anIndex]; 223 | }; 224 | key = [[[NSString stringWithUTF8String:@encode(NSInteger)] dm_stringByRemovingEnodingQualifiers] uppercaseString]; 225 | sDMArgumentsDecoder[key] = decodingBlock; 226 | 227 | decodingBlock = ^(NSInvocation *anInvocation, va_list anArguments, NSInteger anIndex) { 228 | NSUInteger token = va_arg(anArguments, NSUInteger); 229 | [anInvocation setArgument:&token atIndex:anIndex]; 230 | }; 231 | key = [[[NSString stringWithUTF8String:@encode(NSUInteger)] dm_stringByRemovingEnodingQualifiers] uppercaseString]; 232 | sDMArgumentsDecoder[key] = decodingBlock; 233 | 234 | decodingBlock = ^(NSInvocation *anInvocation, va_list anArguments, NSInteger anIndex) { 235 | CGFloat token = va_arg(anArguments, double); 236 | [anInvocation setArgument:&token atIndex:anIndex]; 237 | }; 238 | key = [[[NSString stringWithUTF8String:@encode(double)] dm_stringByRemovingEnodingQualifiers] uppercaseString]; 239 | sDMArgumentsDecoder[key] = decodingBlock; 240 | 241 | decodingBlock = ^(NSInvocation *anInvocation, va_list anArguments, NSInteger anIndex) { 242 | CGPoint token = va_arg(anArguments, CGPoint); 243 | [anInvocation setArgument:&token atIndex:anIndex]; 244 | }; 245 | key = [[[NSString stringWithUTF8String:@encode(CGPoint)] dm_stringByRemovingEnodingQualifiers] uppercaseString]; 246 | sDMArgumentsDecoder[key] = decodingBlock; 247 | 248 | decodingBlock = ^(NSInvocation *anInvocation, va_list anArguments, NSInteger anIndex) { 249 | CGSize token = va_arg(anArguments, CGSize); 250 | [anInvocation setArgument:&token atIndex:anIndex]; 251 | }; 252 | key = [[[NSString stringWithUTF8String:@encode(CGSize)] dm_stringByRemovingEnodingQualifiers] uppercaseString]; 253 | sDMArgumentsDecoder[key] = decodingBlock; 254 | 255 | decodingBlock = ^(NSInvocation *anInvocation, va_list anArguments, NSInteger anIndex) { 256 | CGRect token = va_arg(anArguments, CGRect); 257 | [anInvocation setArgument:&token atIndex:anIndex]; 258 | }; 259 | key = [[[NSString stringWithUTF8String:@encode(CGRect)] dm_stringByRemovingEnodingQualifiers] uppercaseString]; 260 | sDMArgumentsDecoder[key] = decodingBlock; 261 | }); 262 | 263 | NSUInteger count = [aMethodSignature numberOfArguments]; 264 | for (NSUInteger index = 2; index < count; index++) { 265 | NSString *argumentType = [[[NSString stringWithUTF8String:[aMethodSignature getArgumentTypeAtIndex:index]] dm_stringByRemovingEnodingQualifiers] uppercaseString]; 266 | DMDecodingBlock decodingBlock = sDMArgumentsDecoder[argumentType]; 267 | if (decodingBlock == nil) { 268 | abort(); 269 | } else { 270 | decodingBlock(anInvocation, anArguments, index); 271 | } 272 | } 273 | } -------------------------------------------------------------------------------- /Demo/DMAppearance.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 0BC6C3401A95FB33000550BA /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 0BC6C3341A95FB33000550BA /* LaunchScreen.xib */; }; 11 | 0BC6C3411A95FB33000550BA /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0BC6C3361A95FB33000550BA /* Main.storyboard */; }; 12 | 0BC6C3421A95FB33000550BA /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0BC6C3381A95FB33000550BA /* Images.xcassets */; }; 13 | 0BC6C3441A95FB33000550BA /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BC6C33C1A95FB33000550BA /* AppDelegate.m */; }; 14 | 0BC6C3451A95FB33000550BA /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BC6C33D1A95FB33000550BA /* main.m */; }; 15 | 0BC6C3461A95FB33000550BA /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BC6C33F1A95FB33000550BA /* ViewController.m */; }; 16 | 0BC6C34C1A95FC38000550BA /* DMAppearanceRecorder.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BC6C34B1A95FC38000550BA /* DMAppearanceRecorder.m */; }; 17 | 0BC6C3501A96115D000550BA /* Default-568h@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 0BC6C34F1A96115D000550BA /* Default-568h@2x.png */; }; 18 | 0BC6C3571A96149A000550BA /* DMUIObject.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BC6C3561A96149A000550BA /* DMUIObject.m */; }; 19 | 0BC6C35A1A9615A3000550BA /* DMObjectsRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BC6C3591A9615A3000550BA /* DMObjectsRenderer.m */; }; 20 | 0BC6C35D1A9618F7000550BA /* DMUISquare.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BC6C35C1A9618F7000550BA /* DMUISquare.m */; }; 21 | 0BC6C3601A961930000550BA /* DMUIElipse.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BC6C35F1A961930000550BA /* DMUIElipse.m */; }; 22 | 0BC6C3661A961BC2000550BA /* DMView.m in Sources */ = {isa = PBXBuildFile; fileRef = 0BC6C3651A961BC2000550BA /* DMView.m */; }; 23 | /* End PBXBuildFile section */ 24 | 25 | /* Begin PBXFileReference section */ 26 | 0BC6C30A1A95FADB000550BA /* DMAppearanceDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DMAppearanceDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 27 | 0BC6C3351A95FB33000550BA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 28 | 0BC6C3371A95FB33000550BA /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 29 | 0BC6C3381A95FB33000550BA /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 30 | 0BC6C3391A95FB33000550BA /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 31 | 0BC6C33B1A95FB33000550BA /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 32 | 0BC6C33C1A95FB33000550BA /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 33 | 0BC6C33D1A95FB33000550BA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 34 | 0BC6C33E1A95FB33000550BA /* ViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 35 | 0BC6C33F1A95FB33000550BA /* ViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 36 | 0BC6C3491A95FBA8000550BA /* DMAppearance.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = DMAppearance.h; sourceTree = ""; }; 37 | 0BC6C34A1A95FC38000550BA /* DMAppearanceRecorder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DMAppearanceRecorder.h; sourceTree = ""; }; 38 | 0BC6C34B1A95FC38000550BA /* DMAppearanceRecorder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DMAppearanceRecorder.m; sourceTree = ""; }; 39 | 0BC6C34F1A96115D000550BA /* Default-568h@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "Default-568h@2x.png"; sourceTree = ""; }; 40 | 0BC6C3551A96149A000550BA /* DMUIObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DMUIObject.h; sourceTree = ""; }; 41 | 0BC6C3561A96149A000550BA /* DMUIObject.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DMUIObject.m; sourceTree = ""; }; 42 | 0BC6C3581A9615A3000550BA /* DMObjectsRenderer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DMObjectsRenderer.h; sourceTree = ""; }; 43 | 0BC6C3591A9615A3000550BA /* DMObjectsRenderer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DMObjectsRenderer.m; sourceTree = ""; }; 44 | 0BC6C35B1A9618F7000550BA /* DMUISquare.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DMUISquare.h; sourceTree = ""; }; 45 | 0BC6C35C1A9618F7000550BA /* DMUISquare.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DMUISquare.m; sourceTree = ""; }; 46 | 0BC6C35E1A961930000550BA /* DMUIElipse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DMUIElipse.h; sourceTree = ""; }; 47 | 0BC6C35F1A961930000550BA /* DMUIElipse.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DMUIElipse.m; sourceTree = ""; }; 48 | 0BC6C3641A961BC2000550BA /* DMView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DMView.h; sourceTree = ""; }; 49 | 0BC6C3651A961BC2000550BA /* DMView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DMView.m; sourceTree = ""; }; 50 | /* End PBXFileReference section */ 51 | 52 | /* Begin PBXFrameworksBuildPhase section */ 53 | 0BC6C3071A95FADB000550BA /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | ); 58 | runOnlyForDeploymentPostprocessing = 0; 59 | }; 60 | /* End PBXFrameworksBuildPhase section */ 61 | 62 | /* Begin PBXGroup section */ 63 | 0BC6C3011A95FADB000550BA = { 64 | isa = PBXGroup; 65 | children = ( 66 | 0BC6C3471A95FB86000550BA /* DMAppearance */, 67 | 0BC6C33A1A95FB33000550BA /* Sources */, 68 | 0BC6C3331A95FB33000550BA /* Resources */, 69 | 0BC6C30B1A95FADB000550BA /* Products */, 70 | ); 71 | sourceTree = ""; 72 | }; 73 | 0BC6C30B1A95FADB000550BA /* Products */ = { 74 | isa = PBXGroup; 75 | children = ( 76 | 0BC6C30A1A95FADB000550BA /* DMAppearanceDemo.app */, 77 | ); 78 | name = Products; 79 | sourceTree = ""; 80 | }; 81 | 0BC6C3331A95FB33000550BA /* Resources */ = { 82 | isa = PBXGroup; 83 | children = ( 84 | 0BC6C34F1A96115D000550BA /* Default-568h@2x.png */, 85 | 0BC6C3341A95FB33000550BA /* LaunchScreen.xib */, 86 | 0BC6C3361A95FB33000550BA /* Main.storyboard */, 87 | 0BC6C3381A95FB33000550BA /* Images.xcassets */, 88 | 0BC6C3391A95FB33000550BA /* Info.plist */, 89 | ); 90 | path = Resources; 91 | sourceTree = ""; 92 | }; 93 | 0BC6C33A1A95FB33000550BA /* Sources */ = { 94 | isa = PBXGroup; 95 | children = ( 96 | 0BC6C3481A95FB96000550BA /* Model */, 97 | 0BC6C33B1A95FB33000550BA /* AppDelegate.h */, 98 | 0BC6C33C1A95FB33000550BA /* AppDelegate.m */, 99 | 0BC6C33D1A95FB33000550BA /* main.m */, 100 | 0BC6C33E1A95FB33000550BA /* ViewController.h */, 101 | 0BC6C33F1A95FB33000550BA /* ViewController.m */, 102 | 0BC6C3641A961BC2000550BA /* DMView.h */, 103 | 0BC6C3651A961BC2000550BA /* DMView.m */, 104 | ); 105 | path = Sources; 106 | sourceTree = ""; 107 | }; 108 | 0BC6C3471A95FB86000550BA /* DMAppearance */ = { 109 | isa = PBXGroup; 110 | children = ( 111 | 0BC6C3491A95FBA8000550BA /* DMAppearance.h */, 112 | 0BC6C34A1A95FC38000550BA /* DMAppearanceRecorder.h */, 113 | 0BC6C34B1A95FC38000550BA /* DMAppearanceRecorder.m */, 114 | ); 115 | name = DMAppearance; 116 | path = ../DMAppearance; 117 | sourceTree = ""; 118 | }; 119 | 0BC6C3481A95FB96000550BA /* Model */ = { 120 | isa = PBXGroup; 121 | children = ( 122 | 0BC6C3551A96149A000550BA /* DMUIObject.h */, 123 | 0BC6C3561A96149A000550BA /* DMUIObject.m */, 124 | 0BC6C35B1A9618F7000550BA /* DMUISquare.h */, 125 | 0BC6C35C1A9618F7000550BA /* DMUISquare.m */, 126 | 0BC6C35E1A961930000550BA /* DMUIElipse.h */, 127 | 0BC6C35F1A961930000550BA /* DMUIElipse.m */, 128 | 0BC6C3581A9615A3000550BA /* DMObjectsRenderer.h */, 129 | 0BC6C3591A9615A3000550BA /* DMObjectsRenderer.m */, 130 | ); 131 | path = Model; 132 | sourceTree = ""; 133 | }; 134 | /* End PBXGroup section */ 135 | 136 | /* Begin PBXNativeTarget section */ 137 | 0BC6C3091A95FADB000550BA /* DMAppearanceDemo */ = { 138 | isa = PBXNativeTarget; 139 | buildConfigurationList = 0BC6C32D1A95FADB000550BA /* Build configuration list for PBXNativeTarget "DMAppearanceDemo" */; 140 | buildPhases = ( 141 | 0BC6C3061A95FADB000550BA /* Sources */, 142 | 0BC6C3071A95FADB000550BA /* Frameworks */, 143 | 0BC6C3081A95FADB000550BA /* Resources */, 144 | ); 145 | buildRules = ( 146 | ); 147 | dependencies = ( 148 | ); 149 | name = DMAppearanceDemo; 150 | productName = DMAppearance; 151 | productReference = 0BC6C30A1A95FADB000550BA /* DMAppearanceDemo.app */; 152 | productType = "com.apple.product-type.application"; 153 | }; 154 | /* End PBXNativeTarget section */ 155 | 156 | /* Begin PBXProject section */ 157 | 0BC6C3021A95FADB000550BA /* Project object */ = { 158 | isa = PBXProject; 159 | attributes = { 160 | LastUpgradeCheck = 0610; 161 | ORGANIZATIONNAME = "Andrew Gubanov"; 162 | TargetAttributes = { 163 | 0BC6C3091A95FADB000550BA = { 164 | CreatedOnToolsVersion = 6.1.1; 165 | }; 166 | }; 167 | }; 168 | buildConfigurationList = 0BC6C3051A95FADB000550BA /* Build configuration list for PBXProject "DMAppearance" */; 169 | compatibilityVersion = "Xcode 3.2"; 170 | developmentRegion = English; 171 | hasScannedForEncodings = 0; 172 | knownRegions = ( 173 | en, 174 | Base, 175 | ); 176 | mainGroup = 0BC6C3011A95FADB000550BA; 177 | productRefGroup = 0BC6C30B1A95FADB000550BA /* Products */; 178 | projectDirPath = ""; 179 | projectRoot = ""; 180 | targets = ( 181 | 0BC6C3091A95FADB000550BA /* DMAppearanceDemo */, 182 | ); 183 | }; 184 | /* End PBXProject section */ 185 | 186 | /* Begin PBXResourcesBuildPhase section */ 187 | 0BC6C3081A95FADB000550BA /* Resources */ = { 188 | isa = PBXResourcesBuildPhase; 189 | buildActionMask = 2147483647; 190 | files = ( 191 | 0BC6C3421A95FB33000550BA /* Images.xcassets in Resources */, 192 | 0BC6C3401A95FB33000550BA /* LaunchScreen.xib in Resources */, 193 | 0BC6C3501A96115D000550BA /* Default-568h@2x.png in Resources */, 194 | 0BC6C3411A95FB33000550BA /* Main.storyboard in Resources */, 195 | ); 196 | runOnlyForDeploymentPostprocessing = 0; 197 | }; 198 | /* End PBXResourcesBuildPhase section */ 199 | 200 | /* Begin PBXSourcesBuildPhase section */ 201 | 0BC6C3061A95FADB000550BA /* Sources */ = { 202 | isa = PBXSourcesBuildPhase; 203 | buildActionMask = 2147483647; 204 | files = ( 205 | 0BC6C3601A961930000550BA /* DMUIElipse.m in Sources */, 206 | 0BC6C34C1A95FC38000550BA /* DMAppearanceRecorder.m in Sources */, 207 | 0BC6C3661A961BC2000550BA /* DMView.m in Sources */, 208 | 0BC6C3461A95FB33000550BA /* ViewController.m in Sources */, 209 | 0BC6C35A1A9615A3000550BA /* DMObjectsRenderer.m in Sources */, 210 | 0BC6C3571A96149A000550BA /* DMUIObject.m in Sources */, 211 | 0BC6C3451A95FB33000550BA /* main.m in Sources */, 212 | 0BC6C35D1A9618F7000550BA /* DMUISquare.m in Sources */, 213 | 0BC6C3441A95FB33000550BA /* AppDelegate.m in Sources */, 214 | ); 215 | runOnlyForDeploymentPostprocessing = 0; 216 | }; 217 | /* End PBXSourcesBuildPhase section */ 218 | 219 | /* Begin PBXVariantGroup section */ 220 | 0BC6C3341A95FB33000550BA /* LaunchScreen.xib */ = { 221 | isa = PBXVariantGroup; 222 | children = ( 223 | 0BC6C3351A95FB33000550BA /* Base */, 224 | ); 225 | name = LaunchScreen.xib; 226 | sourceTree = ""; 227 | }; 228 | 0BC6C3361A95FB33000550BA /* Main.storyboard */ = { 229 | isa = PBXVariantGroup; 230 | children = ( 231 | 0BC6C3371A95FB33000550BA /* Base */, 232 | ); 233 | name = Main.storyboard; 234 | sourceTree = ""; 235 | }; 236 | /* End PBXVariantGroup section */ 237 | 238 | /* Begin XCBuildConfiguration section */ 239 | 0BC6C32B1A95FADB000550BA /* Debug */ = { 240 | isa = XCBuildConfiguration; 241 | buildSettings = { 242 | ALWAYS_SEARCH_USER_PATHS = NO; 243 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 244 | CLANG_CXX_LIBRARY = "libc++"; 245 | CLANG_ENABLE_MODULES = YES; 246 | CLANG_ENABLE_OBJC_ARC = YES; 247 | CLANG_WARN_BOOL_CONVERSION = YES; 248 | CLANG_WARN_CONSTANT_CONVERSION = YES; 249 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 250 | CLANG_WARN_EMPTY_BODY = YES; 251 | CLANG_WARN_ENUM_CONVERSION = YES; 252 | CLANG_WARN_INT_CONVERSION = YES; 253 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 254 | CLANG_WARN_UNREACHABLE_CODE = YES; 255 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 256 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 257 | COPY_PHASE_STRIP = NO; 258 | ENABLE_STRICT_OBJC_MSGSEND = YES; 259 | GCC_C_LANGUAGE_STANDARD = gnu99; 260 | GCC_DYNAMIC_NO_PIC = NO; 261 | GCC_OPTIMIZATION_LEVEL = 0; 262 | GCC_PREPROCESSOR_DEFINITIONS = ( 263 | "DEBUG=1", 264 | "$(inherited)", 265 | ); 266 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 267 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 268 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 269 | GCC_WARN_UNDECLARED_SELECTOR = YES; 270 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 271 | GCC_WARN_UNUSED_FUNCTION = YES; 272 | GCC_WARN_UNUSED_VARIABLE = YES; 273 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 274 | MTL_ENABLE_DEBUG_INFO = YES; 275 | ONLY_ACTIVE_ARCH = YES; 276 | SDKROOT = iphoneos; 277 | }; 278 | name = Debug; 279 | }; 280 | 0BC6C32C1A95FADB000550BA /* Release */ = { 281 | isa = XCBuildConfiguration; 282 | buildSettings = { 283 | ALWAYS_SEARCH_USER_PATHS = NO; 284 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 285 | CLANG_CXX_LIBRARY = "libc++"; 286 | CLANG_ENABLE_MODULES = YES; 287 | CLANG_ENABLE_OBJC_ARC = YES; 288 | CLANG_WARN_BOOL_CONVERSION = YES; 289 | CLANG_WARN_CONSTANT_CONVERSION = YES; 290 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 291 | CLANG_WARN_EMPTY_BODY = YES; 292 | CLANG_WARN_ENUM_CONVERSION = YES; 293 | CLANG_WARN_INT_CONVERSION = YES; 294 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 295 | CLANG_WARN_UNREACHABLE_CODE = YES; 296 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 297 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 298 | COPY_PHASE_STRIP = YES; 299 | ENABLE_NS_ASSERTIONS = NO; 300 | ENABLE_STRICT_OBJC_MSGSEND = YES; 301 | GCC_C_LANGUAGE_STANDARD = gnu99; 302 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 303 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 304 | GCC_WARN_UNDECLARED_SELECTOR = YES; 305 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 306 | GCC_WARN_UNUSED_FUNCTION = YES; 307 | GCC_WARN_UNUSED_VARIABLE = YES; 308 | IPHONEOS_DEPLOYMENT_TARGET = 8.1; 309 | MTL_ENABLE_DEBUG_INFO = NO; 310 | SDKROOT = iphoneos; 311 | VALIDATE_PRODUCT = YES; 312 | }; 313 | name = Release; 314 | }; 315 | 0BC6C32E1A95FADB000550BA /* Debug */ = { 316 | isa = XCBuildConfiguration; 317 | buildSettings = { 318 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 319 | INFOPLIST_FILE = Resources/Info.plist; 320 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 321 | PRODUCT_NAME = "$(TARGET_NAME)"; 322 | }; 323 | name = Debug; 324 | }; 325 | 0BC6C32F1A95FADB000550BA /* Release */ = { 326 | isa = XCBuildConfiguration; 327 | buildSettings = { 328 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 329 | INFOPLIST_FILE = Resources/Info.plist; 330 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 331 | PRODUCT_NAME = "$(TARGET_NAME)"; 332 | }; 333 | name = Release; 334 | }; 335 | /* End XCBuildConfiguration section */ 336 | 337 | /* Begin XCConfigurationList section */ 338 | 0BC6C3051A95FADB000550BA /* Build configuration list for PBXProject "DMAppearance" */ = { 339 | isa = XCConfigurationList; 340 | buildConfigurations = ( 341 | 0BC6C32B1A95FADB000550BA /* Debug */, 342 | 0BC6C32C1A95FADB000550BA /* Release */, 343 | ); 344 | defaultConfigurationIsVisible = 0; 345 | defaultConfigurationName = Release; 346 | }; 347 | 0BC6C32D1A95FADB000550BA /* Build configuration list for PBXNativeTarget "DMAppearanceDemo" */ = { 348 | isa = XCConfigurationList; 349 | buildConfigurations = ( 350 | 0BC6C32E1A95FADB000550BA /* Debug */, 351 | 0BC6C32F1A95FADB000550BA /* Release */, 352 | ); 353 | defaultConfigurationIsVisible = 0; 354 | defaultConfigurationName = Release; 355 | }; 356 | /* End XCConfigurationList section */ 357 | }; 358 | rootObject = 0BC6C3021A95FADB000550BA /* Project object */; 359 | } 360 | -------------------------------------------------------------------------------- /Demo/DMAppearance.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Demo/Resources/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /Demo/Resources/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Demo/Resources/Default-568h@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andrewgubanov/DMAppearance/c3b6b54d4a4bd93d8ab904573a7debab95f760e0/Demo/Resources/Default-568h@2x.png -------------------------------------------------------------------------------- /Demo/Resources/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Demo/Resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | CompanyName.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Demo/Sources/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // DMAppearance 4 | // 5 | // Created by Andrew Gubanov on 19/02/15. 6 | // Copyright (c) 2015 Andrew Gubanov. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /Demo/Sources/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // DMAppearance 4 | // 5 | // Created by Andrew Gubanov on 19/02/15. 6 | // Copyright (c) 2015 Andrew Gubanov. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | // Override point for customization after application launch. 20 | return YES; 21 | } 22 | 23 | - (void)applicationWillResignActive:(UIApplication *)application { 24 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 25 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 26 | } 27 | 28 | - (void)applicationDidEnterBackground:(UIApplication *)application { 29 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 30 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 31 | } 32 | 33 | - (void)applicationWillEnterForeground:(UIApplication *)application { 34 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication *)application { 38 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 39 | } 40 | 41 | - (void)applicationWillTerminate:(UIApplication *)application { 42 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 43 | } 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /Demo/Sources/DMView.h: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // DMView.h 4 | // DMAppearance 5 | // 6 | // Created by Andrew Gubanov on 19/02/15. 7 | // Copyright 2015 Andrew Gubanov. All rights reserved. 8 | // 9 | // 10 | 11 | @import UIKit; 12 | 13 | @class DMObjectsRenderer; 14 | 15 | @interface DMView : UIView 16 | @property (nonatomic, strong) DMObjectsRenderer *renderer; 17 | @end 18 | -------------------------------------------------------------------------------- /Demo/Sources/DMView.m: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // DMView.m 4 | // DMAppearance 5 | // 6 | // Created by Andrew Gubanov on 19/02/15. 7 | // Copyright 2015 Andrew Gubanov. All rights reserved. 8 | // 9 | // 10 | 11 | #import "DMView.h" 12 | #import "DMObjectsRenderer.h" 13 | 14 | @interface DMView () 15 | @end 16 | 17 | @implementation DMView 18 | 19 | - (void)setRenderer:(DMObjectsRenderer *)aRenderer 20 | { 21 | if (_renderer != aRenderer) { 22 | _renderer = aRenderer; 23 | [self setNeedsDisplay]; 24 | } 25 | } 26 | 27 | - (void)drawRect:(CGRect)aRect 28 | { 29 | CGContextRef context = UIGraphicsGetCurrentContext(); 30 | [self.renderer renderInContex:context]; 31 | } 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Demo/Sources/Model/DMObjectsRenderer.h: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // DMObjectsRenderer.h 4 | // DMAppearance 5 | // 6 | // Created by Andrew Gubanov on 19/02/15. 7 | // Copyright 2015 Andrew Gubanov. All rights reserved. 8 | // 9 | // 10 | 11 | @import Foundation; 12 | @import CoreGraphics; 13 | 14 | @class DMUIObject; 15 | 16 | @interface DMObjectsRenderer : NSObject 17 | 18 | - (instancetype)initWithRootObject:(DMUIObject *)aRoot NS_DESIGNATED_INITIALIZER; 19 | - (void)renderInContex:(CGContextRef)aContext; 20 | 21 | @property (atomic, strong, readonly) DMUIObject *root; 22 | @end 23 | -------------------------------------------------------------------------------- /Demo/Sources/Model/DMObjectsRenderer.m: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // DMObjectsRenderer.m 4 | // DMAppearance 5 | // 6 | // Created by Andrew Gubanov on 19/02/15. 7 | // Copyright 2015 Andrew Gubanov. All rights reserved. 8 | // 9 | // 10 | 11 | #import "DMObjectsRenderer.h" 12 | #import "DMUIObject.h" 13 | 14 | @interface DMObjectsRenderer () 15 | @property (atomic, strong, readwrite) DMUIObject *root; 16 | - (void)renderRecursivelyInContext:(CGContextRef)aContext rootObject:(DMUIObject *)aRoot clipFrame:(CGRect)aFrame; 17 | @end 18 | 19 | @implementation DMObjectsRenderer 20 | 21 | - (id)initWithRootObject:(DMUIObject *)aRoot 22 | { 23 | self = [super init]; 24 | if (self != nil) { 25 | self.root = aRoot; 26 | [aRoot willMoveToRenderer]; 27 | } 28 | return self; 29 | } 30 | 31 | - (void)renderInContex:(CGContextRef)aContext 32 | { 33 | CGRect clipFrame = CGContextGetClipBoundingBox(aContext); 34 | CGRect rootClipFrame = [DMUIObject convertFromParentRect:clipFrame toUIObject:self.root]; 35 | [self renderRecursivelyInContext:aContext rootObject:self.root clipFrame:rootClipFrame]; 36 | } 37 | 38 | #pragma mark Private 39 | - (void)renderRecursivelyInContext:(CGContextRef)aContext rootObject:(DMUIObject *)aRoot clipFrame:(CGRect)aFrame 40 | { 41 | BOOL needRender = [aRoot intersectWithRect:aFrame]; 42 | if (needRender) { 43 | CGContextSaveGState(aContext); 44 | CGContextTranslateCTM(aContext, aRoot.frame.origin.x, aRoot.frame.origin.y); 45 | [aRoot renderInContext:aContext]; 46 | for (DMUIObject *child in aRoot.children) { 47 | CGRect childClipFrame = [DMUIObject convertFromParentRect:aFrame toUIObject:child]; 48 | [self renderRecursivelyInContext:aContext rootObject:child clipFrame:childClipFrame]; 49 | } 50 | CGContextRestoreGState(aContext); 51 | } 52 | } 53 | 54 | @end 55 | -------------------------------------------------------------------------------- /Demo/Sources/Model/DMUIElipse.h: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // DMUIElipse.h 4 | // DMAppearance 5 | // 6 | // Created by Andrew Gubanov on 19/02/15. 7 | // Copyright 2015 Andrew Gubanov. All rights reserved. 8 | // 9 | // 10 | 11 | @import UIKit; 12 | #import "DMUIObject.h" 13 | 14 | @interface DMUIElipse : DMUIObject 15 | @property (atomic, strong) UIColor *fillColor; 16 | @end 17 | -------------------------------------------------------------------------------- /Demo/Sources/Model/DMUIElipse.m: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // DMUIElipse.m 4 | // DMAppearance 5 | // 6 | // Created by Andrew Gubanov on 19/02/15. 7 | // Copyright 2015 Andrew Gubanov. All rights reserved. 8 | // 9 | // 10 | 11 | #import "DMUIElipse.h" 12 | 13 | @interface DMUIElipse () 14 | @end 15 | 16 | @implementation DMUIElipse 17 | 18 | - (void)renderInContext:(CGContextRef)aContext 19 | { 20 | CGContextSaveGState(aContext); 21 | CGContextSetFillColorWithColor(aContext, self.fillColor.CGColor); 22 | CGContextFillEllipseInRect(aContext, self.bounds); 23 | CGContextRestoreGState(aContext); 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Demo/Sources/Model/DMUIObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // DMUIObject.h 4 | // DMAppearance 5 | // 6 | // Created by Andrew Gubanov on 19/02/15. 7 | // Copyright 2015 Andrew Gubanov. All rights reserved. 8 | // 9 | // 10 | 11 | @import Foundation; 12 | @import CoreGraphics; 13 | #import "DMAppearance.h" 14 | 15 | @interface DMUIObject : NSObject 16 | 17 | - (instancetype)initWithCGFrame:(CGRect)aFrame NS_DESIGNATED_INITIALIZER; 18 | - (void)renderInContext:(CGContextRef)aContext; 19 | 20 | + (CGRect)convertFromParentRect:(CGRect)aRect toUIObject:(DMUIObject *)anObject; 21 | - (BOOL)intersectWithRect:(CGRect)aRect; 22 | 23 | @property (atomic, assign) CGRect frame; 24 | @property (atomic, assign, readonly) CGRect bounds; 25 | 26 | @property (atomic, weak, readonly) DMUIObject *parent; 27 | @property (atomic, copy, readonly) NSArray *children; 28 | - (void)addChild:(DMUIObject *)aChild; 29 | - (void)removeFromParent; 30 | 31 | - (void)willMoveToRenderer; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /Demo/Sources/Model/DMUIObject.m: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // DMUIObject.m 4 | // DMAppearance 5 | // 6 | // Created by Andrew Gubanov on 19/02/15. 7 | // Copyright 2015 Andrew Gubanov. All rights reserved. 8 | // 9 | // 10 | 11 | #import "DMUIObject.h" 12 | #import "DMAppearanceRecorder.h" 13 | 14 | @interface DMUIObject () 15 | @property (atomic, strong) NSMutableArray *mutableChildren; 16 | @property (atomic, weak, readwrite) DMUIObject *parent; 17 | @end 18 | 19 | @implementation DMUIObject 20 | 21 | + (instancetype)appearance 22 | { 23 | return (id)[DMAppearanceRecorder appearanceRecorderForClass:self]; 24 | } 25 | 26 | - (instancetype)initWithCGFrame:(CGRect)aFrame 27 | { 28 | self = [super init]; 29 | if (self != nil) { 30 | self.frame = aFrame; 31 | self.mutableChildren = [NSMutableArray array]; 32 | } 33 | return self; 34 | } 35 | 36 | - (void)renderInContext:(CGContextRef)aContext 37 | { 38 | } 39 | 40 | - (void)addChild:(DMUIObject *)aChild 41 | { 42 | if (aChild != nil) 43 | { 44 | aChild.parent = self; 45 | [self.mutableChildren addObject:aChild]; 46 | } 47 | } 48 | 49 | - (void)removeFromParent 50 | { 51 | DMUIObject *parent = self.parent; 52 | [parent.mutableChildren removeObject:self]; 53 | self.parent = nil; 54 | } 55 | 56 | - (BOOL)intersectWithRect:(CGRect)aRect 57 | { 58 | return CGRectIntersectsRect(aRect, self.bounds); 59 | } 60 | 61 | - (NSArray *)children 62 | { 63 | return [NSArray arrayWithArray:self.mutableChildren]; 64 | } 65 | 66 | + (CGRect)convertFromParentRect:(CGRect)aRect toUIObject:(DMUIObject *)anObject; 67 | { 68 | CGRect childFrame = anObject.frame; 69 | CGRect result = CGRectMake(CGRectGetMinX(aRect) - CGRectGetMinX(childFrame), CGRectGetMinY(aRect) - CGRectGetMinY(childFrame), 70 | CGRectGetWidth(aRect), CGRectGetHeight(aRect)); 71 | return result; 72 | } 73 | 74 | - (CGRect)bounds 75 | { 76 | CGRect result = {{0,0}, self.frame.size}; 77 | return result; 78 | } 79 | 80 | - (void)willMoveToRenderer 81 | { 82 | [[DMAppearanceRecorder appearanceRecorderForClass:[self class]] applyAppearanceForTarget:self]; 83 | [self.children makeObjectsPerformSelector:@selector(willMoveToRenderer)]; 84 | } 85 | @end 86 | -------------------------------------------------------------------------------- /Demo/Sources/Model/DMUISquare.h: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // DMUISquare.h 4 | // DMAppearance 5 | // 6 | // Created by Andrew Gubanov on 19/02/15. 7 | // Copyright 2015 Andrew Gubanov. All rights reserved. 8 | // 9 | // 10 | 11 | @import UIKit; 12 | #import "DMUIObject.h" 13 | 14 | @interface DMUISquare : DMUIObject 15 | @property (atomic, strong) UIColor *fillColor; 16 | @end 17 | -------------------------------------------------------------------------------- /Demo/Sources/Model/DMUISquare.m: -------------------------------------------------------------------------------- 1 | // 2 | // 3 | // DMUISquare.m 4 | // DMAppearance 5 | // 6 | // Created by Andrew Gubanov on 19/02/15. 7 | // Copyright 2015 Andrew Gubanov. All rights reserved. 8 | // 9 | // 10 | 11 | #import "DMUISquare.h" 12 | 13 | @interface DMUISquare () 14 | @end 15 | 16 | @implementation DMUISquare 17 | 18 | - (void)renderInContext:(CGContextRef)aContext 19 | { 20 | CGContextSaveGState(aContext); 21 | CGContextSetFillColorWithColor(aContext, self.fillColor.CGColor); 22 | CGContextFillRect(aContext, self.bounds); 23 | CGContextRestoreGState(aContext); 24 | } 25 | @end 26 | -------------------------------------------------------------------------------- /Demo/Sources/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // DMAppearance 4 | // 5 | // Created by Andrew Gubanov on 19/02/15. 6 | // Copyright (c) 2015 Andrew Gubanov. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /Demo/Sources/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // DMAppearance 4 | // 5 | // Created by Andrew Gubanov on 19/02/15. 6 | // Copyright (c) 2015 Andrew Gubanov. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "DMUIElipse.h" 11 | #import "DMUISquare.h" 12 | #import "DMObjectsRenderer.h" 13 | #import "DMView.h" 14 | 15 | @interface ViewController () 16 | @end 17 | 18 | @implementation ViewController 19 | 20 | - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 21 | { 22 | self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 23 | if (self != nil) { 24 | 25 | } 26 | return self; 27 | } 28 | 29 | - (void)awakeFromNib 30 | { 31 | [super awakeFromNib]; 32 | DMUIElipse *appearance = [DMUIElipse appearance]; 33 | appearance.fillColor = [UIColor redColor]; 34 | } 35 | 36 | - (void)viewDidLoad { 37 | [super viewDidLoad]; 38 | 39 | DMUISquare *root = [[DMUISquare alloc] initWithCGFrame:self.view.bounds]; 40 | root.fillColor = [UIColor blackColor]; 41 | 42 | DMUIElipse *elipse = [[DMUIElipse alloc] initWithCGFrame:CGRectMake(100.0f, 100.0f, 40.f, 40.0f)]; //default fill color 43 | [root addChild:elipse]; 44 | 45 | elipse = [[DMUIElipse alloc] initWithCGFrame:CGRectMake(200.0f, 100.0f, 40.f, 40.0f)]; 46 | elipse.fillColor = [UIColor greenColor]; 47 | [root addChild:elipse]; 48 | 49 | DMObjectsRenderer *renderer = [[DMObjectsRenderer alloc] initWithRootObject:root]; 50 | [(DMView *)self.view setRenderer:renderer]; 51 | } 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /Demo/Sources/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // DMAppearance 4 | // 5 | // Created by Andrew Gubanov on 19/02/15. 6 | // Copyright (c) 2015 Andrew Gubanov. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Andrew Gubanov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DMAppearance 2 | Custom proxy with partial UIApearance functionality to facilitate appearance sweets for any other object apart from UIKit ones. 3 | This implementation keeps track of the original method calls and does not apply the style from appearance to the reciever for those methods. 4 | 5 | ## How To Use 6 | ``` objc 7 | @interface MyObject : NSObject 8 | @property (nonatomic, copy) NSString *name; 9 | @end 10 | 11 | @implementation MyObject 12 | 13 | + (instancetype)appearance 14 | { 15 | return (id)[DMAppearanceRecorder appearanceRecorderForClass:self]; 16 | } 17 | @end 18 | 19 | ``` 20 | Then, when your object is ready to accept appearance styling you can call: 21 | ``` objc 22 | [[DMAppearanceRecorder appearanceRecorderForClass:[self class]] applyAppearanceForTarget:self]; 23 | ``` 24 | 25 | Somewhere in your code where you would use MyObject: 26 | ``` objc 27 | MyObject *appearance = [MyObject appearance]; 28 | appearance.name = @"Shared name"; 29 | ``` 30 | 31 | And somewhere else: 32 | ``` objc 33 | MyObject *myObject = [[MyObject alloc] init]; 34 | NSLog(@"%@", myObject.name); 35 | 36 | myObject = [[MyObject alloc] init]; 37 | myObject.name = @"Custom name"; 38 | NSLog(@"%@", myObject.name); 39 | ``` 40 | Dispalyed result would be: 41 | ``` objc 42 | "Shared name" 43 | "Custom name" 44 | ``` 45 | 46 | You can alse refer to Demo project for mode details. 47 | 48 | ## Installation 49 | 50 | DMAppearance is available through [CocoaPods](http://cocoapods.org). To install 51 | it, simply add the following line to your Podfile: 52 | 53 | pod "DMAppearance" 54 | --------------------------------------------------------------------------------