Skip to content

Instantly share code, notes, and snippets.

@heumn
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heumn/523ed28cc2d153c4c529 to your computer and use it in GitHub Desktop.
Save heumn/523ed28cc2d153c4c529 to your computer and use it in GitHub Desktop.
Fonts and colors in plist
//i header
//megaphone table view cell settings
@property (nonatomic, strong) UIFont *megaphoneStatementFont;
@property (nonatomic, strong) UIColor *megaphoneStatementFontColor;
@property (nonatomic, strong) UIFont *megaphoneUserNameFont;
@property (nonatomic, strong) UIColor *megaphoneUserNameFontColor;
@property (nonatomic, strong) UIFont *megaphoneLoadingFont;
@property (nonatomic, strong) UIColor *megaphoneLoadingFontColor;
...
//implementering
//megaphone table view cell settings
[self fontAndColorWithDictionary:fontsAndColors dictionaryKey:@"MegaphoneStatementFont"];
[self fontAndColorWithDictionary:fontsAndColors dictionaryKey:@"MegaphoneUserNameFont"];
[self fontAndColorWithDictionary:fontsAndColors dictionaryKey:@"MegaphoneLoadingFont"];
....
#pragma mark - Private helper methods
- (UIColor*)colorWithDictionary:(NSDictionary*)dictionary
{
float red = [(NSNumber*)[dictionary objectForKey:@"Red"] floatValue] / MAX_COLOR_VALUE;
float green = [(NSNumber*)[dictionary objectForKey:@"Green"] floatValue] / MAX_COLOR_VALUE;
float blue = [(NSNumber*)[dictionary objectForKey:@"Blue"] floatValue] / MAX_COLOR_VALUE;
float alpha = [(NSNumber*)[dictionary objectForKey:@"Alpha"] floatValue] / MAX_COLOR_VALUE;
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}
- (UIFont*)fontWithDictionary:(NSDictionary*)dictionary
{
return [UIFont fontWithName:(NSString*)[dictionary objectForKey:@"Name"] size:[(NSNumber*) [dictionary objectForKey:@"Size"] floatValue]];
}
- (void)fontAndColorWithDictionary:(NSDictionary*)dictionary dictionaryKey:(NSString*)dictionaryKey {
NSDictionary *dictFont = (NSDictionary*)[dictionary objectForKey:dictionaryKey];
[self setValue:[self fontWithDictionary:dictFont] forKey:dictionaryKey];
[self setValue:[self colorWithDictionary:(NSDictionary*)[dictFont objectForKey:KEY_COLOR]] forKey:[NSString stringWithFormat:@"%@%@", dictionaryKey, KEY_COLOR]];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment