码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 设置RGB色的宏

时间:2014-08-14 10:24:48      阅读:249      评论:0      收藏:0      [点我收藏+]

标签:blog   http   color   os   io   for   div   amp   

转自:http://lizhuang.iteye.com/blog/1931768

?//RGB Color macro
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
  
//RGB color macro with alpha
#define UIColorFromRGBWithAlpha(rgbValue,a) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:a]
  
  
//16进制字符串 转换为int
+ (id)colorWithHex:(NSString *)hex alpha:(CGFloat)alpha
{
    NSAssert(7 == hex.length, @"Hex color format error!");
      
    unsigned color = 0;
    NSScanner *hexValueScanner = [NSScanner scannerWithString:[hex substringFromIndex:1]];
    [hexValueScanner scanHexInt:&color];
  
    int blue = color & 0xFF;
    int green = (color >> 8) & 0xFF;
    int red = (color >> 16) & 0xFF;
          
    return [UIColor colorWithRed:red/255.0 green:green/255.0 blue:blue/255.0 alpha:1.0];
}  ?

iOS 设置RGB色的宏,布布扣,bubuko.com

iOS 设置RGB色的宏

标签:blog   http   color   os   io   for   div   amp   

原文地址:http://www.cnblogs.com/jz319/p/3911775.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!