2017.03.05-2017.05.23
1.融云获取最后一条消息的内容
RCConversation *conversation = [[RCIMClient sharedRCIMClient]getConversation:ConversationType_PRIVATE targetId:[NSString stringWithFormat:@"%lu",(long)model.trainee_id]];
if ([conversation.senderUserId isEqualToString:[[RCIM sharedRCIM]currentUserInfo].userId]) {
cell.timeLabel.text = [self timestampConversionDate:conversation.sentTime/1000];
}else {
if (conversation.receivedTime != 0) {
cell.timeLabel.text = [self timestampConversionDate:conversation.receivedTime/1000];
}else {
cell.timeLabel.text = @"00:00";
}
}
if (conversation.unreadMessageCount > 0) {
cell.statusView.hidden = NO;
}else {
cell.statusView.hidden = YES;
}
if ([conversation.lastestMessage isKindOfClass:[RCTextMessage class]]) {
cell.contentLabel.text =((RCTextMessage *)conversation.lastestMessage).content;
}else if ([conversation.lastestMessage isMemberOfClass:[RCVoiceMessage class]]) {
cell.contentLabel.text = @"[语音]";
}else if([conversation.lastestMessage isMemberOfClass:[RCLocationMessage class]]) {
cell.contentLabel.text =((RCLocationMessage *)conversation.lastestMessage).locationName;
}else if([conversation.lastestMessage isMemberOfClass:[RCImageMessage class]]) {
cell.contentLabel.text = @"[图片]";
}else {
cell.contentLabel.text = @"暂无聊天信息";
}
2.与Android对接是需带上用户信息
///连接融云
- (void) rongCloudSetting {
NSString *token = [[NSUserDefaults standardUserDefaults]objectForKey:k_Rong_Token];
[[RCIM sharedRCIM] connectWithToken:token success:^(NSString *userId) {
NSLog(@"***登录成功");
RCUserInfo *userinfo = [[RCUserInfo alloc]initWithUserId:[RCIM sharedRCIM].currentUserInfo.userId name: [[NSUserDefaults standardUserDefaults] objectForKey:k_User_Name] portrait:[[NSUserDefaults standardUserDefaults] objectForKey:k_User_HeadImage]];
[[RCIM sharedRCIM] setCurrentUserInfo:userinfo];
[[RCIM sharedRCIM] setEnableMessageAttachUserInfo:YES];
} error:^(RCConnectErrorCode status) {
NSLog(@"***登录失败");
} tokenIncorrect:^{
NSLog(@"token过期或不正确");
}];
}
3.提交数据时主window蒙一层防重点
//FactoryClass为自己定义的工厂类
- (void) addFaceViewSetting {
UIWindow *keywindow = [[UIApplication sharedApplication] keyWindow];
self.loadBgView = [FactoryClass CreateView:0 Rounded:0 ToView:keywindow];
self.loadBgView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.25];
[self.loadBgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.top.equalTo(keywindow);
make.bottom.equalTo(keywindow);
}];
self.loadBgView.hidden = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapNoClickEvent)];
tap.delegate = self;
[self.loadBgView addGestureRecognizer:tap];
}
4. 比较时间
- (NSInteger) compareStr:(NSString *)timeStr{
if (timeStr.length < 22) {
return -2;
}
NSString *dayStr = [timeStr substringToIndex:10];
NSString *hourOneStr = [timeStr substringToIndex:16];
NSString *hourStr = [timeStr substringFromIndex:timeStr.length - 5];
NSString *houTwoStr = [NSString stringWithFormat:@"%@ %@",dayStr,hourStr];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *currentDateStr = [dateFormatter stringFromDate:[NSDate date]];
NSDate *dateA = [dateFormatter dateFromString:hourOneStr];
NSDate *dateB = [dateFormatter dateFromString:houTwoStr];
NSDate *dateC = [dateFormatter dateFromString:currentDateStr];
NSComparisonResult result_1 = [dateC compare:dateA];
NSComparisonResult result_2 = [dateC compare:dateB];
//相等
if (result_1 == NSOrderedAscending) {
return -1;
}
//在某个时间段内
if ((result_1 == NSOrderedDescending || result_1 == NSOrderedSame)&&(result_2 == NSOrderedAscending || result_2 == NSOrderedSame)) {
return 0;
}
//超过了某个时间
else if (result_2 == NSOrderedDescending){
return 1;
}
return -2;
}
5.高级控件控制其某类cell是否可以被点击
//开启高级控件的多选
self.collectionView.allowsMultipleSelection = YES;
//是否可以被点击
if (schedule.order == -1) {
cell.userInteractionEnabled = NO;
cell.bgView.backgroundColor = [UIColor colorWithRGB:color(FFFFFF)];
}else if(schedule.order == -2) {
cell.userInteractionEnabled = YES;
cell.bgView.backgroundColor = [UIColor colorWithRGB:color(FFB300)];
}else if(schedule.order == 0) {
cell.userInteractionEnabled = YES;
cell.bgView.backgroundColor = [UIColor colorWithRGB:color(65C66E)];
}else if(schedule.order > 0) {
cell.userInteractionEnabled = YES;
cell.bgView.backgroundColor = [UIColor colorWithRGB:[UIColor colorWithMain]];
}else {
cell.userInteractionEnabled = NO;
cell.bgView.backgroundColor = [UIColor colorWithRGB:color(FFFFFF)];
}
}
6.创建带有图片的富文本
- (NSAttributedString *) insertImageWithLabel:(NSString *)imageName Text:(NSString *)text {
// 创建一个富文本
NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@ ",text]];
[attri addAttributes:@{NSForegroundColorAttributeName:[UIColor colorWithRGB:[UIColor colorWithMain]]} range:NSMakeRange(0, attri.length)];
// 添加表情
NSTextAttachment *attch = [[NSTextAttachment alloc] init];
// 表情图片
attch.image = [UIImage imageNamed:imageName];
// 设置图片大小
attch.bounds = CGRectMake(0, 0, Size(16), Size(30));
// 创建带有图片的富文本
NSAttributedString *string = [NSAttributedString attributedStringWithAttachment:attch];
[attri insertAttributedString:string atIndex:attri.length];
//返回
return attri;
}
7. 时间字符串转某种格式
///NSString转NSDate
- (NSDictionary *) stringConverseDate:(NSString *)dateStr {
if (dateStr == nil) {
return nil;
}
//需要转换的字符串
NSString *dateString = dateStr;
//设置转换格式
NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
[formatter setDateFormat:@"yyyy-MM-dd"];
//NSString转NSDate
NSDate *date=[formatter dateFromString:dateString];
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EEE"];
NSString *weekStr = [dateFormat stringFromDate:date];
[dateFormat setDateFormat:@"MM-dd"];
NSString *dayStr = [dateFormat stringFromDate:date];
if (weekStr == nil || dayStr == nil) {
return nil;
}
//判断当前手机系统的语言选择
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
NSString *currentLanguage = [languages objectAtIndex:0];
if ([currentLanguage isEqualToString:@"zh_Hans"]) {
NSString *weekRstr = [NSString stringWithFormat:@"周%@",[weekStr substringFromIndex:weekStr.length-1]];
return [[NSDictionary alloc]initWithObjectsAndKeys:weekRstr,@"Week",dayStr,@"MandD", nil];
}else {
return [[NSDictionary alloc]initWithObjectsAndKeys:weekStr,@"Week",dayStr,@"MandD", nil];
}
}
8.移除键盘通知和定时器
- (void)dealloc {
[self.codeTimer invalidate];
self.codeTimer = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillChangeFrameNotification object:nil];
}
9.限制输入框的输入长度和限制输入字符
#pragma mark - UITextFieldDeledate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
if (textField == self.phoneTextField) {
if (toBeString.length > 11) {
return NO;
}
}
if (textField == self.codeTextField) {
if (toBeString.length > 6) {
return NO;
}
}
if (textField == self.passwordTextField) {
if (toBeString.length > 22) {
return NO;
}
}
if (textField == self.againPasswordTextField) {
if (toBeString.length > 22) {
return NO;
}
}
//如果输入的字符串不满足某种格式就不能输入
if (![YFWLValidationMessage checkUserName:((UITextField *)self.textFieldArray[0]).text]) {
[YFWLHUDManager showInfoMessage:@"姓名格式错误" duration:1.3];
return NO;
}
return YES;
}
10.正则匹配手机号、身份证、密码和银行卡等格式
#pragma 正则匹配手机号
+ (BOOL)checkTelNumber:(NSString *) telNumber
{
NSString *pattern = @"^1+[3578]+\\d{9}";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
BOOL isMatch = [pred evaluateWithObject:telNumber];
return isMatch;
}
#pragma 正则匹配用户密码6-22位数字和字母组合
+ (BOOL)checkPassword:(NSString *) password
{
NSString *pattern = @"^(?![0-9]+$)[a-zA-Z0-9]{6,22}";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
BOOL isMatch = [pred evaluateWithObject:password];
return isMatch;
}
#pragma 正则匹配用户姓名,20位的中文或英文
+ (BOOL)checkUserName : (NSString *) userName
{
NSString *pattern = @"^[a-zA-Z\u4E00-\u9FA5]{1,20}";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
BOOL isMatch = [pred evaluateWithObject:userName];
return isMatch;
}
#pragma 正则匹配用户身份证号15或18位
+ (BOOL)checkUserIdCard: (NSString *) idCard
{
NSString *pattern = @"(^[0-9]{15}$)|([0-9]{17}([0-9]|X)$)";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
BOOL isMatch = [pred evaluateWithObject:idCard];
return isMatch;
}
#pragma 正则验证码,6位的数字
+ (BOOL)checkEmployeeNumber : (NSString *) number
{
NSString *pattern = @"^[0-9]{6}";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
BOOL isMatch = [pred evaluateWithObject:number];
return isMatch;
}
#pragma 正则匹配URL
+ (BOOL)checkURL : (NSString *) url
{
NSString *pattern = @"^[0-9A-Za-z]{1,50}";
NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", pattern];
BOOL isMatch = [pred evaluateWithObject:url];
return isMatch;
}
#pragma 匹配银行卡
+ (BOOL) IsBankCard:(NSString *)cardNumber
{
if(cardNumber.length==0)
{
return NO;
}
NSString *digitsOnly = @"";
char c;
for (int i = 0; i < cardNumber.length; i++)
{
c = [cardNumber characterAtIndex:i];
if (isdigit(c))
{
digitsOnly =[digitsOnly stringByAppendingFormat:@"%c",c];
}
}
int sum = 0;
int digit = 0;
int addend = 0;
BOOL timesTwo = false;
for (NSInteger i = digitsOnly.length - 1; i >= 0; i--)
{
digit = [digitsOnly characterAtIndex:i] - '0';
if (timesTwo)
{
addend = digit * 2;
if (addend > 9) {
addend -= 9;
}
}
else {
addend = digit;
}
sum += addend;
timesTwo = !timesTwo;
}
int modulus = sum % 10;
return modulus == 0;
}
11.判断手机当前类型
//创建方法:给UIDevice建立类别并导入这个头文件#import <sys/utsname.h> 如:@implementation UIDevice (YFWLGetDevice)
//使用方法: [UIDevice deviceModelName];//直接返回当前的手机类型
+ (NSString*)deviceModelName
{
struct utsname systemInfo;
uname(&systemInfo);
NSString *deviceModel = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
//iPhone 系列
if ([deviceModel isEqualToString:@"iPhone1,1"]) return @"iPhone 1G";
if ([deviceModel isEqualToString:@"iPhone1,2"]) return @"iPhone 3G";
if ([deviceModel isEqualToString:@"iPhone2,1"]) return @"iPhone 3GS";
if ([deviceModel isEqualToString:@"iPhone3,1"]) return @"iPhone 4";
if ([deviceModel isEqualToString:@"iPhone3,2"]) return @"iPhone 4";
if ([deviceModel isEqualToString:@"iPhone4,1"]) return @"iPhone 4S";
if ([deviceModel isEqualToString:@"iPhone5,1"]) return @"iPhone 5";
if ([deviceModel isEqualToString:@"iPhone5,2"]) return @"iPhone 5";
if ([deviceModel isEqualToString:@"iPhone5,3"]) return @"iPhone 5C";
if ([deviceModel isEqualToString:@"iPhone5,4"]) return @"iPhone 5C";
if ([deviceModel isEqualToString:@"iPhone6,1"]) return @"iPhone 5S";
if ([deviceModel isEqualToString:@"iPhone6,2"]) return @"iPhone 5S";
if ([deviceModel isEqualToString:@"iPhone7,1"]) return @"iPhone6 Plus";
if ([deviceModel isEqualToString:@"iPhone7,2"]) return @"iPhone6";
if ([deviceModel isEqualToString:@"iPhone8,1"]) return @"iPhone6s";
if ([deviceModel isEqualToString:@"iPhone8,2"]) return @"iPhone6s Plus";
if ([deviceModel isEqualToString:@"iPhone9,1"]) return @"iPhone7 (CDMA)";
if ([deviceModel isEqualToString:@"iPhone9,3"]) return @"iPhone7 (GSM)";
if ([deviceModel isEqualToString:@"iPhone9,2"]) return @"iPhone7 Plus (CDMA)";
if ([deviceModel isEqualToString:@"iPhone9,4"]) return @"iPhone7 Plus (GSM)";
//iPod 系列
if ([deviceModel isEqualToString:@"iPod1,1"]) return @"iPod Touch 1G";
if ([deviceModel isEqualToString:@"iPod2,1"]) return @"iPod Touch 2G";
if ([deviceModel isEqualToString:@"iPod3,1"]) return @"iPod Touch 3G";
if ([deviceModel isEqualToString:@"iPod4,1"]) return @"iPod Touch 4G";
if ([deviceModel isEqualToString:@"iPod5,1"]) return @"iPod Touch 5G";
//iPad 系列
if ([deviceModel isEqualToString:@"iPad1,1"]) return @"iPad";
if ([deviceModel isEqualToString:@"iPad2,1"]) return @"iPad 2 (WiFi)";
if ([deviceModel isEqualToString:@"iPad2,2"]) return @"iPad 2 (GSM)";
if ([deviceModel isEqualToString:@"iPad2,3"]) return @"iPad 2 (CDMA)";
if ([deviceModel isEqualToString:@"iPad2,4"]) return @"iPad 2 (32nm)";
if ([deviceModel isEqualToString:@"iPad2,5"]) return @"iPad mini (WiFi)";
if ([deviceModel isEqualToString:@"iPad2,6"]) return @"iPad mini (GSM)";
if ([deviceModel isEqualToString:@"iPad2,7"]) return @"iPad mini (CDMA)";
if ([deviceModel isEqualToString:@"iPad3,1"]) return @"iPad 3(WiFi)";
if ([deviceModel isEqualToString:@"iPad3,2"]) return @"iPad 3(CDMA)";
if ([deviceModel isEqualToString:@"iPad3,3"]) return @"iPad 3(4G)";
if ([deviceModel isEqualToString:@"iPad3,4"]) return @"iPad 4 (WiFi)";
if ([deviceModel isEqualToString:@"iPad3,5"]) return @"iPad 4 (4G)";
if ([deviceModel isEqualToString:@"iPad3,6"]) return @"iPad 4 (CDMA)";
if ([deviceModel isEqualToString:@"iPad4,1"]) return @"iPad Air";
if ([deviceModel isEqualToString:@"iPad4,2"]) return @"iPad Air";
if ([deviceModel isEqualToString:@"iPad4,3"]) return @"iPad Air";
if ([deviceModel isEqualToString:@"iPad5,3"]) return @"iPad Air 2";
if ([deviceModel isEqualToString:@"iPad5,4"]) return @"iPad Air 2";
if ([deviceModel isEqualToString:@"i386"]) return @"Simulator";
if ([deviceModel isEqualToString:@"x86_64"]) return @"Simulator";
if ([deviceModel isEqualToString:@"iPad4,4"]
||[deviceModel isEqualToString:@"iPad4,5"]
||[deviceModel isEqualToString:@"iPad4,6"]) return @"iPad mini 2";
if ([deviceModel isEqualToString:@"iPad4,7"]
||[deviceModel isEqualToString:@"iPad4,8"]
||[deviceModel isEqualToString:@"iPad4,9"]) return @"iPad mini 3";
return deviceModel;
}
12.自己解析字符串数组
格式: @"["B1","B2","C1","C2"]"
- (void) loadDataFouncation {
NSMutableString *strMu = [[NSMutableString alloc]init];
if (self.isSelectCars) {
NSString *string = [[NSUserDefaults standardUserDefaults]objectForKey:k_Car_Style];
strMu = [[NSMutableString alloc]initWithString:string];
}else {
NSString *string = [[NSUserDefaults standardUserDefaults]objectForKey:k_License_Style];
strMu = [[NSMutableString alloc]initWithString:string];
}
[strMu replaceOccurrencesOfString:@"[" withString:@"" options:0 range:NSMakeRange(0, strMu.length)];
[strMu replaceOccurrencesOfString:@"\"" withString:@"" options:0 range:NSMakeRange(0, strMu.length)];
[strMu replaceOccurrencesOfString:@"]" withString:@"" options:0 range:NSMakeRange(0, strMu.length)];
NSArray *arrTemp = [strMu componentsSeparatedByString:@","];
[arrTemp enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[self.dataArray addObject:obj];
}];
[self.collectionView reloadData];
}
13.点击缩略图放大图片
创建方法:创建一个NSObject类,将此代码拷贝到.m文件中,.h中申明两个类方法
使用方法:[类名 scanBigImageWithImageArray:图片数组 CurrentIndex:当前下标];
//原始尺寸
static CGRect oldframe;
/**
* 浏览单张大图
*
* @param currentImageview 图片所在的imageView
*/
+(void)scanBigImageWithImageView:(UIImageView *)currentImageview{
//当前imageview的图片
UIImage *image = currentImageview.image;
//当前视图
UIWindow *window = [UIApplication sharedApplication].keyWindow;
//背景
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
//当前imageview的原始尺寸->将像素currentImageview.bounds由currentImageview.bounds所在视图转换到目标视图window中,返回在目标视图window中的像素值
oldframe = [currentImageview convertRect:currentImageview.bounds toView:window];
[backgroundView setBackgroundColor:[UIColor colorWithRGB:color(000000)]];
//此时视图不会显示
[backgroundView setAlpha:0];
//将所展示的imageView重新绘制在Window中
UIImageView *imageView = [[UIImageView alloc] initWithFrame:oldframe];
[imageView setImage:image];
[imageView setTag:0];
[backgroundView addSubview:imageView];
//将原始视图添加到背景视图中
[window addSubview:backgroundView];
//添加点击事件同样是类方法 -> 作用是再次点击回到初始大小
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideImageView:)];
[backgroundView addGestureRecognizer:tapGestureRecognizer];
//动画放大所展示的ImageView
[UIView animateWithDuration:0.4 animations:^{
CGFloat y,width,height;
y = ([UIScreen mainScreen].bounds.size.height - image.size.height * [UIScreen mainScreen].bounds.size.width / image.size.width) * 0.5;
//宽度为屏幕宽度
width = [UIScreen mainScreen].bounds.size.width;
//高度 根据图片宽高比设置
height = image.size.height * [UIScreen mainScreen].bounds.size.width / image.size.width;
[imageView setFrame:CGRectMake(0, y, width, height)];
//重要! 将视图显示出来
[backgroundView setAlpha:1];
} completion:^(BOOL finished) {
}];
}
/**
* 浏览数组大图,并带偏移量
*
* @param currentImageArray 图片所在的imageView
*/
+(void)scanBigImageWithImageArray:(NSMutableArray *)currentImageArray CurrentIndex:(NSInteger)currentIndex {
//当前视图
UIWindow *window = [UIApplication sharedApplication].keyWindow;
//背景
UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
[backgroundView setBackgroundColor:[UIColor colorWithRGB:color(000000)]];
//此时视图不会显示
[backgroundView setAlpha:0];
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:backgroundView.bounds];
scrollView.pagingEnabled = YES;
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;
scrollView.bounces = NO;
scrollView.scrollEnabled = YES;
scrollView.contentSize = CGSizeMake(kMainScreenWidth * currentImageArray.count, kMainScreenHeight);
[backgroundView addSubview:scrollView];
for (NSInteger i = 0; i < currentImageArray.count; i++) {
NSString *currentURL = currentImageArray[i];
UIImageView *currentImageview = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kMainScreenWidth, kMainScreenHeight)];
[currentImageview sd_setImageWithURL:[NSURL URLWithString:currentURL] placeholderImage:[UIImage imageNamed:@"banner"]];
currentImageview.contentMode = UIViewContentModeScaleAspectFit;
currentImageview.origin = CGPointMake(kMainScreenWidth * i, 0);
currentImageview.centerY = scrollView.centerY;
[scrollView addSubview:currentImageview];
}
scrollView.contentOffset = CGPointMake(kMainScreenWidth*currentIndex, 0);
//将原始视图添加到背景视图中
[window addSubview:backgroundView];
//添加点击事件同样是类方法 -> 作用是再次点击回到初始大小
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideImageView:)];
[backgroundView addGestureRecognizer:tapGestureRecognizer];
//动画放大所展示的ImageView
[UIView animateWithDuration:0.4 animations:^{
[backgroundView setAlpha:1];
} completion:^(BOOL finished) {
}];
}
/**
* 恢复imageView原始尺寸
*
* @param tap 点击事件
*/
+(void)hideImageView:(UITapGestureRecognizer *)tap{
UIView *backgroundView = tap.view;
//原始imageview
UIImageView *imageView = [tap.view viewWithTag:0];
//恢复
[UIView animateWithDuration:0.2 animations:^{
[imageView setFrame:oldframe];
[backgroundView setAlpha:0];
} completion:^(BOOL finished) {
//完成后操作->将背景视图删掉
[backgroundView removeFromSuperview];
}];
}
14.给UIColor添加类别
使用实例:
///导航栏的颜色值
+ (UIColor *)colorWithNavigationBar {
return [UIColor colorWithRGB:color(CB3340)];
}
#pragma 十六进制转RGB值
+ (UIColor *)colorWithRGB:(uint32_t)rgbValue {
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0f
green:((rgbValue & 0xFF00) >> 8) / 255.0f
blue:(rgbValue & 0xFF) / 255.0f
alpha:1];
}
#pragma 十六进制转RGBA值
+ (UIColor *)colorWithRGBA:(uint32_t)rgbaValue {
return [UIColor colorWithRed:((rgbaValue & 0xFF000000) >> 24) / 255.0f
green:((rgbaValue & 0xFF0000) >> 16) / 255.0f
blue:((rgbaValue & 0xFF00) >> 8) / 255.0f
alpha:(rgbaValue & 0xFF) / 255.0f];
}
#pragma 十六进制转RGBA值
+ (UIColor *)colorWithRGB:(uint32_t)rgbValue alpha:(CGFloat)alpha {
return [UIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0f
green:((rgbValue & 0xFF00) >> 8) / 255.0f
blue:(rgbValue & 0xFF) / 255.0f
alpha:alpha];
}