Skip to content

Instantly share code, notes, and snippets.

@soemarko
Created May 26, 2013 19:16
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 soemarko/5653735 to your computer and use it in GitHub Desktop.
Save soemarko/5653735 to your computer and use it in GitHub Desktop.
Extending UIColor ... and extend more as needed. Hex conversion from http://stackoverflow.com/questions/4265161/how-to-convert-hexadecimal-to-rgb
//
// UIColor+Colours.h
//
// Created by Soemarko Ridwan on 25/05/13.
// Copyright (c) 2013 Soemarko Ridwan. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIColor (Colours)
// accepts 0xff00aa
+(UIColor *)colorWithRGBHex:(UInt32)hex withAlpha:(float)alpha;
+(UIColor *)whiteColorWithAlpha:(float)alpha;
+(UIColor *)blackColorWithAlpha:(float)alpha;
+(UIColor *)antiFlashWhiteColor;
+(UIColor *)blackOliveColor;
@end
//
// UIColor+Colours.m
//
// Created by Soemarko Ridwan on 25/05/13.
// Copyright (c) 2013 Soemarko Ridwan. All rights reserved.
//
#import "UIColor+Colours.h"
@implementation UIColor (Colours)
+(UIColor *)colorWithRGBHex:(UInt32)hex withAlpha:(float)alpha {
int r = (hex >> 16) & 0xFF;
int g = (hex >> 8) & 0xFF;
int b = (hex) & 0xFF;
return [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:alpha];
}
+(UIColor *)whiteColorWithAlpha:(float)alpha {
return [UIColor colorWithRed:255.0/255.0 green:255.0/255.0 blue:255.0/255.0 alpha:alpha];
}
+(UIColor *)blackColorWithAlpha:(float)alpha {
return [UIColor colorWithRed:0 green:0 blue:0 alpha:alpha];
}
+(UIColor *)antiFlashWhiteColor {
return [UIColor colorWithRed:242.0/255.0 green:243.0/255.0 blue:244.0/255.0 alpha:1.0];
}
+(UIColor *)blackOliveColor {
return [UIColor colorWithRed:59.0/255.0 green:60.0/255.0 blue:54.0/255.0 alpha:1.0];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment