diff --git a/Demo/DB5Demo.xcodeproj/project.pbxproj b/Demo/DB5Demo.xcodeproj/project.pbxproj index dac0ee5..8f1d0de 100644 --- a/Demo/DB5Demo.xcodeproj/project.pbxproj +++ b/Demo/DB5Demo.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 6AABDD3617802886003DFA59 /* DB5-alt.json in Resources */ = {isa = PBXBuildFile; fileRef = 6AABDD3517802886003DFA59 /* DB5-alt.json */; }; 840375F5177BD9A600188A0B /* VSTheme.m in Sources */ = {isa = PBXBuildFile; fileRef = 840375F2177BD9A600188A0B /* VSTheme.m */; }; 840375F6177BD9A600188A0B /* VSThemeLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 840375F4177BD9A600188A0B /* VSThemeLoader.m */; }; 840375F8177BDA9E00188A0B /* DB5.plist in Resources */ = {isa = PBXBuildFile; fileRef = 840375F7177BDA9E00188A0B /* DB5.plist */; }; @@ -24,6 +25,7 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 6AABDD3517802886003DFA59 /* DB5-alt.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "DB5-alt.json"; sourceTree = ""; }; 840375F1177BD9A600188A0B /* VSTheme.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VSTheme.h; path = ../../Source/VSTheme.h; sourceTree = ""; }; 840375F2177BD9A600188A0B /* VSTheme.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VSTheme.m; path = ../../Source/VSTheme.m; sourceTree = ""; }; 840375F3177BD9A600188A0B /* VSThemeLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VSThemeLoader.h; path = ../../Source/VSThemeLoader.h; sourceTree = ""; }; @@ -101,6 +103,7 @@ 840375F1177BD9A600188A0B /* VSTheme.h */, 840375F2177BD9A600188A0B /* VSTheme.m */, 840375F7177BDA9E00188A0B /* DB5.plist */, + 6AABDD3517802886003DFA59 /* DB5-alt.json */, 844CCE17177B6B5900B8BDF0 /* Supporting Files */, ); path = DB5Demo; @@ -173,6 +176,7 @@ buildActionMask = 2147483647; files = ( 844CCE1B177B6B5900B8BDF0 /* InfoPlist.strings in Resources */, + 6AABDD3617802886003DFA59 /* DB5-alt.json in Resources */, 844CCE23177B6B5900B8BDF0 /* Default.png in Resources */, 844CCE25177B6B5900B8BDF0 /* Default@2x.png in Resources */, 844CCE27177B6B5900B8BDF0 /* Default-568h@2x.png in Resources */, diff --git a/Demo/DB5Demo/DB5-alt.json b/Demo/DB5Demo/DB5-alt.json new file mode 100644 index 0000000..ba53309 --- /dev/null +++ b/Demo/DB5Demo/DB5-alt.json @@ -0,0 +1,16 @@ +{ + "Default": { + "labelX": 44, + "labelY": 300, + "labelAnimationCurve": "easeout", + "labelFontSize": 18, + "labelFont": "Avenir-Medium", + "labelTextColor": "333333", + "labelAnimationDuration": 0.25, + "backgroundColor": "708090", + "labelAnimationDelay": 2 + }, + "Example Theme": { + "test": "foo" + } +} diff --git a/README.md b/README.md index c33f488..bf7dcaa 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ There is nothing magical about the code or the system: it’s some simple code p ### How it works -See the demo app. You include two classes — VSThemeLoader and VSTheme — and DB5.plist. The plist is where you set values. +See the demo app. You include two classes — VSThemeLoader and VSTheme — and DB5.plist. The plist is where you set values. You can use a JSON file too, if you prefer. At startup you load the file via VSThemeLoader, then access values via methods in VSTheme. diff --git a/Source/VSThemeLoader.m b/Source/VSThemeLoader.m index bbbe4c6..461137b 100644 --- a/Source/VSThemeLoader.m +++ b/Source/VSThemeLoader.m @@ -9,7 +9,6 @@ #import "VSThemeLoader.h" #import "VSTheme.h" - @interface VSThemeLoader () @property (nonatomic, strong, readwrite) VSTheme *defaultTheme; @@ -26,8 +25,18 @@ - (id)init { if (self == nil) return nil; - NSString *themesFilePath = [[NSBundle mainBundle] pathForResource:@"DB5" ofType:@"plist"]; - NSDictionary *themesDictionary = [NSDictionary dictionaryWithContentsOfFile:themesFilePath]; + NSString *filename = @"DB5"; + NSDictionary *themesDictionary; + NSString *themesFilePath = [[NSBundle mainBundle] pathForResource:filename ofType:@"plist"]; + if (themesFilePath != nil) { + themesDictionary = [NSDictionary dictionaryWithContentsOfFile:themesFilePath]; + } else { + themesFilePath = [[NSBundle mainBundle] pathForResource:filename ofType:@"json"]; + NSInputStream *stream = [NSInputStream inputStreamWithFileAtPath:themesFilePath]; + [stream open]; + themesDictionary = [NSJSONSerialization JSONObjectWithStream:stream options:0 error:nil]; + [stream close]; + } NSMutableArray *themes = [NSMutableArray array]; for (NSString *oneKey in themesDictionary) {