zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
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
//
//  UIColor+ZJFAdditon.m
//  ProBIM
//
//  Created by zjf on 2017/12/25.
//  Copyright © 2017年 ProBIM. All rights reserved.
//
 
#import "UIColor+ZJFAdditon.h"
 
@implementation UIColor (ZJFAdditon)
+ (instancetype)z_colorWithHex:(uint32_t)hex alpha:(CGFloat)alpha {
    //hex = 0xA3 B2 FF
    int red = (hex & 0xFF0000) >> 16;
    int green = (hex & 0x00FF00) >> 8;
    int blue = (hex & 0x0000FF);
    return [UIColor z_colorWithR:red G:green B:blue alpha:alpha];
}
+ (instancetype)z_colorWithR:(int)red G:(int)green B:(int)blue alpha:(CGFloat)alpha {
    return [UIColor colorWithRed:red / 255.0 green:green / 255.0 blue:blue / 255.0 alpha:alpha];
}
+ (instancetype)z_colorWithHex:(uint32_t)hex {
    int red = (hex & 0xFF0000) >> 16;
    int green = (hex & 0x00FF00) >> 8;
    int blue = (hex & 0x0000FF);
    return [UIColor z_colorWithR:red G:green B:blue alpha:1.0];
}
+ (instancetype)z_colorWithR:(int)red G:(int)green B:(int)blue {
    return [UIColor colorWithRed:red / 255.0 green:green / 255.0 blue:blue / 255.0 alpha:1.0];
}
+ (instancetype)z_randomColor {
    return [UIColor z_colorWithR:arc4random_uniform(256) G:arc4random_uniform(256) B:arc4random_uniform(256) alpha:1];
}
@end