Skip to content

Instantly share code, notes, and snippets.

@ohsc
Created December 31, 2011 05:15
Show Gist options
  • Save ohsc/1542973 to your computer and use it in GitHub Desktop.
Save ohsc/1542973 to your computer and use it in GitHub Desktop.
Enable hex value with UIColor
//
// UIColor+Hex.h
//
//
// Created by 超 沈 on 11-12-31.
// Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIColor (Hex)
+ (UIColor*)colorWithHex:(NSInteger)hexValue alpha:(CGFloat)alphaValue;
+ (UIColor*)colorWithHex:(NSInteger)hexValue;
+ (UIColor*)whiteColorWithAlpha:(CGFloat)alphaValue;
+ (UIColor*)blackColorWithAlpha:(CGFloat)alphaValue;
@end
//
// UIColor+Hex.m
//
//
// Created by 超 沈 on 11-12-31.
// Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//
#import "UIColor+Hex.h"
@implementation UIColor (Hex)
+ (UIColor*)colorWithHex:(NSInteger)hexValue alpha:(CGFloat)alphaValue
{
return [UIColor colorWithRed:((float)((hexValue & 0xFF0000) >> 16))/255.0
green:((float)((hexValue & 0xFF00) >> 8))/255.0
blue:((float)(hexValue & 0xFF))/255.0 alpha:alphaValue];
}
+ (UIColor*)colorWithHex:(NSInteger)hexValue
{
return [UIColor colorWithHex:hexValue alpha:1.0];
}
+ (UIColor*)whiteColorWithAlpha:(CGFloat)alphaValue
{
return [UIColor colorWithHex:0xffffff alpha:alphaValue];
}
+ (UIColor*)blackColorWithAlpha:(CGFloat)alphaValue
{
return [UIColor colorWithHex:0x000000 alpha:alphaValue];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment