Provide resources independently of your code. Manage different sizes, strings depending on the device type or orientation. Inspired in the Resource management of Android.
Easily extended, you can provide your own criterias. e.g. handle different values depending on your product jurisdictions.
It is inspired by the resource management in Android . It is a simpler version, with less rules, and adapted to the iOS ecosystem.
You can create resource files that apply only when some criterias are meet. You can create a resource file name "resources-ipad-land.plist". and another "resources-ipad-port.plist". If you are using an ipad in landscape the values returned will be from the first file.
The rules are defined in the following table, each configuration has its own qualifier values that you can use in your resource filename.
Configuration | Qualifier values | Description |
---|---|---|
Device model | e.g. ipad iphone iphone6 iphon6plus | Specify the device model. You can be specific to apply the rule to more cases, or have a criteria more generic |
Orientation | e.g. port land | Device orientation |
The first step is to create your resource files with .plist extension, with your criterias.
Create a MDResourceManager and give it your criterias. Bear in mind that the order is important, the best match algoritm considers the order you give your criterias.
You can also create your own criterias.
NSArray *criterias = @[[[MDDeviceResourceCriteria alloc] init],
[[MDOrientationResourceCriteria alloc] init]];
MDResourceManager *resourceManager = [[MDResourceManager alloc] initWithPrefixFileName:@"dimensions"
criterias:criterias];
[resourceManager loadResources];
CGFloat labelFontSize1 = [resourceManager floatForKey:@"labelFontSize1"];
CGFloat labelFontSize2 = [resourceManager floatForKey:@"labelFontSize2"];
To run the example project, clone the repo, and run pod install
from the Example directory first.
MDResourceManager is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "MDResourceManager"
Joao Prudencio, joao.prudencio@mindera.com
MDResourceManager is available under the MIT license. See the LICENSE file for more info.