Last active
August 29, 2015 14:00
-
-
Save bentford/11254014 to your computer and use it in GitHub Desktop.
Example of a iOS Stylesheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// StyleUtil.m | |
#import "StyleUtil.h" | |
// Normally I'll import UIColor+Hex.h | |
// but for sake of the gist, I included the category inline | |
// #import "UIColor+Hex.h" | |
NSUInteger intFromHexChar(char c) { | |
if ( c >= '0' && c <= '9' ) | |
return [[NSNumber numberWithChar:c] intValue] - '0'; | |
switch ( c ) { | |
case 'A': | |
case 'a': | |
return 10; | |
case 'B': | |
case 'b': | |
return 11; | |
case 'C': | |
case 'c': | |
return 12; | |
case 'D': | |
case 'd': | |
return 13; | |
case 'E': | |
case 'e': | |
return 14; | |
case 'F': | |
case 'f': | |
return 15; | |
default: return 0; | |
} | |
} | |
@implementation UIColor(Hex) | |
+ (UIColor *)extColorFromHexString:(NSString *)hexString withAlpha:(CGFloat)alpha | |
{ | |
if( [hexString length] == 7 ) | |
hexString = [hexString substringFromIndex:1]; | |
if( [hexString length] != 6 ) | |
return [UIColor blackColor]; | |
CGFloat rgb[3] = {0,0,0}; | |
int rgbIndex=0; | |
for ( NSInteger i = 0; i < [hexString length]; i=i+2 ) { | |
NSUInteger firstCharacter = intFromHexChar([hexString characterAtIndex:i]); | |
firstCharacter = firstCharacter << 4; | |
NSUInteger secondCharacter = intFromHexChar([hexString characterAtIndex:i+1]); | |
firstCharacter += secondCharacter; | |
rgb[rgbIndex++] = (CGFloat)(firstCharacter/255.0); | |
} | |
return [UIColor colorWithRed:rgb[0] green:rgb[1] blue:rgb[2] alpha:alpha]; | |
} | |
+ (UIColor *)extColorFromHexString:(NSString *)hexString | |
{ | |
return [UIColor extColorFromHexString:hexString withAlpha:1.0f]; | |
} | |
- (NSString *)extRGBString | |
{ | |
CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha = 0.0; | |
[self getRed:&red green:&green blue:&blue alpha:&alpha]; | |
return [NSString stringWithFormat:@"%02lX%02lX%02lX", (unsigned long)(red*255.0f), (unsigned long)(green*255.0f), (unsigned long)(blue*255.0f)]; | |
} | |
@end | |
@implementation StyleUtil | |
+ (UIFont *)standardFontWithSize:(CGFloat)size | |
{ | |
return [UIFont fontWithName:@"Avenir-Light" size:size]; | |
} | |
+ (UIFont *)titleFontWithSize:(CGFloat)size | |
{ | |
return [UIFont fontWithName:@"Avenir-Roman" size:size]; | |
} | |
+ (UIFont *)italicFontWithSize:(CGFloat)size | |
{ | |
return [UIFont fontWithName:@"AvenirNext-Italic" size:size]; | |
} | |
+ (UIFont *)boldFontWithSize:(CGFloat)size | |
{ | |
return [UIFont fontWithName:@"AvenirNext-Heavy" size:size]; | |
} | |
+ (UIFont *)boldSerifFontWithSize:(CGFloat)size | |
{ | |
return [UIFont fontWithName:@"Baskerville-SemiBold" size:size]; | |
} | |
+ (UIFont *)semiBoldFontWithSize:(CGFloat)size | |
{ | |
return [UIFont fontWithName:@"AvenirNext-DemiBold" size:size]; | |
} | |
+ (UIButton *)standardButtonWithText:(NSString *)text | |
{ | |
// make button here | |
UIButton *button = nil; | |
return button; | |
} | |
+ (UIColor *)inspirationColor | |
{ | |
return [UIColor extColorFromHexString:@"878cc5"]; | |
} | |
+ (UIColor *)listColor | |
{ | |
return [UIColor extColorFromHexString:@"fbb97d"]; | |
} | |
+ (UIColor *)exhibitionColor | |
{ | |
return [UIColor extColorFromHexString:@"bacfc5"]; | |
} | |
+ (UIColor *)socialColor | |
{ | |
return [UIColor extColorFromHexString:@"57cbf5"]; | |
} | |
+ (UIColor *)eventColor | |
{ | |
return [UIColor extColorFromHexString:@"f69898"]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment