Last active
August 29, 2015 14:02
-
-
Save Alex04/b8624750f74cbf73c6d2 to your computer and use it in GitHub Desktop.
UIColor+Extensions.h
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
// | |
// UIColor+Extension.h | |
// | |
// Copyright (c) 2013 ama-dev.com. All rights reserved. | |
// Created by Alexander Mack on 12.02.13. | |
// | |
#import <UIKit/UIKit.h> | |
typedef struct { | |
float red; | |
float green; | |
float blue; | |
float alpha; | |
} AMARGBColor; | |
static inline AMARGBColor AMARGBColorMake(float red, float green, float blue, float alpha) { | |
AMARGBColor amaColor; | |
amaColor.red = red; | |
amaColor.green = green; | |
amaColor.blue = blue; | |
amaColor.alpha = alpha; | |
return amaColor; | |
} | |
static inline AMARGBColor AMARGBColorMakeEqualWithAlpha(float general, float alpha) { | |
AMARGBColor amaColor; | |
amaColor.red = general; | |
amaColor.green = general; | |
amaColor.blue = general; | |
amaColor.alpha = alpha; | |
return amaColor; | |
} | |
static inline AMARGBColor AMARGBColorMakeEqual(float general) { | |
AMARGBColor amaColor; | |
amaColor.red = general; | |
amaColor.green = general; | |
amaColor.blue = general; | |
amaColor.alpha = 1.0f; | |
return amaColor; | |
} | |
@interface UIColor (Extension) | |
+ (UIColor *) colorWithRGB:(AMARGBColor) aRGBColor; | |
+ (UIColor *) colorWithHex:(u_int) aHex; | |
+ (UIColor *) colorWithHexString:(NSString *) aHexString; | |
@end |
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
// | |
// UIColor+Extension.h | |
// | |
// Copyright (c) 2013 ama-dev.com. All rights reserved. | |
// Created by Alexander Mack on 12.02.13. | |
// | |
#import "UIColor+Extension.h" | |
@implementation UIColor (Extension) | |
+ (UIColor *) colorWithRGB:(AMARGBColor) aRGBColor; | |
{ | |
return [UIColor colorWithRed:aRGBColor.red/255.0f green:aRGBColor.green/255.0f blue:aRGBColor.blue/255.0f alpha:aRGBColor.alpha]; | |
} | |
+ (UIColor *) colorWithHex:(u_int) aHex; | |
{ | |
int red = (aHex & 0xFF0000) >> 16; | |
int green = (aHex & 0x00FF00) >> 8; | |
int blue = aHex & 0x0000FF; | |
return [UIColor colorWithRGB:AMARGBColorMake(red, green, blue, 1)]; | |
} | |
+ (UIColor *) colorWithHexString:(NSString *) aHexString; | |
{ | |
unsigned hexValue = 0; | |
[[NSScanner scannerWithString:[aHexString stringByReplacingOccurrencesOfString:@"#" withString:@"0x"]] scanHexInt:&hexValue]; | |
return [UIColor colorWithHex:hexValue]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment