---
title: "颜色设置"
author: "修博龙泉"
date: "2013-04-27T09:50:18Z"
tags: []
categories: ["移动开发"]
slug: "untitled"
draft: false
lastmod: "2013-04-27T09:50:18Z"
id: 1855677
url: "https://longquan.iteye.com/blog/1855677"
---

```java

[globle colorfromhexrgb:@"bb0b15"]
+ (UIColor *)colorFromHexRGB:(NSString *)inColorString
{
    UIColor *result = nil;
    unsigned int colorCode = 0;
    unsigned char redByte, greenByte, blueByte;
    
    if (nil != inColorString)
    {
        NSScanner *scanner = [nsscanner scannerwithstring:incolorstring];
        (void) [scanner scanhexint:&colorcode]; // ignore error
    }
    redByte = (unsigned char) (colorCode >> 16);
    greenByte = (unsigned char) (colorCode >> 8);
    blueByte = (unsigned char) (colorCode); // masks off high bits
    result = [uicolor
              colorwithred: (float)redbyte / 0xff
              green: (float)greenbyte/ 0xff
              blue: (float)bluebyte / 0xff
              alpha:1.0];
    return result;
}

```