文章標題

/**
將16進制的顏色值變成UIColor @”FFFF00”
*/
+(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;

}

發佈了33 篇原創文章 · 獲贊 5 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章