-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIColor+RGB.m
37 lines (30 loc) · 1.03 KB
/
UIColor+RGB.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//
// UIColor+RGB.m
// btaInsurance
//
// Created by Mustafin Askar on 19.03.13.
// Copyright (c) 2013 askar. All rights reserved.
//
#import "UIColor+RGB.h"
@implementation UIColor (RGB)
+ (UIColor *)fromRGB:(int)RGBValueInHEX
{
return [self fromRGB:RGBValueInHEX andAlpha:1.0];
}
+ (UIColor *)fromRGB:(int)RGBValueInHEX andAlpha:(float)alpha
{
return [UIColor colorWithRed:((float)((RGBValueInHEX & 0xFF0000) >> 16))/255.0 green:((float)((RGBValueInHEX & 0xFF00) >> 8))/255.0 blue:((float)(RGBValueInHEX & 0xFF))/255.0 alpha:alpha];
}
+ (UIImage *)imageFromColor:(UIColor *)color width:(float)width height:(float)height
{
CGRect rect = CGRectMake(0, 0, width, height);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context,
[color CGColor]);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
@end