根据十六进制返回对应颜色

<span style="color:#009900;">UIColor+Extension.h文件</span>
//
//  UIColor+Extension.h
//  NothingTest
//
//  Created by James on 16/3/24.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface UIColor (Extension)
/**
 *  返回对应的十六进制颜色
 *
 *  @param color 十六进制颜色
 *
 *  @return 转换后的颜色
 */
+ (instancetype)LJ_colorWithHex:(uint32_t)color;
@end
<span style="color:#009900;background-color: rgb(255, 255, 255);">UIColor+Extension.m文件</span>
<pre name="code" class="objc">//
//  UIColor+Extension.m
//  NothingTest
//
//  Created by James on 16/3/24.
//  Copyright © 2016年 Apple. All rights reserved.
//

#import "UIColor+Extension.h"

@implementation UIColor (Extension)

+ (instancetype)LJ_colorWithHex:(uint32_t)color {
    /**
     *  color分别做&运算 分别计算RGB
     */
    int red = color & 0xFF0000;
    
    int green = color & 0x00FF00;
    
    int blue = color & 0x0000FF;
    
    return  [UIColor colorWithRed:red / 255.0 green:green /255.0 blue:blue /255.0 alpha:1];
}
@end



                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值