iOS/Swift + Objective-c

[objective-c] Hex Color를 UIColor로 변환하기 (Hex to UIColor)

안경 쓴 귀니 2021. 8. 2. 23:12
반응형

Hex 컬러를 UIColor로 변환하는 방법

Utils.m

+(UIColor *)colorWithRGBHex:(NSUInteger)RGBHex alpha:(CGFloat)alpha {
    CGFloat red = ((CGFloat)((RGBHex & 0xFF0000) >> 16)) / 255.0f;
    CGFloat green = ((CGFloat)((RGBHex & 0xFF00) >> 8)) / 255.0f;
    CGFloat blue = ((CGFloat)((RGBHex & 0xFF))) / 255.0f;
    return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
}

 

사용 방법

UIColor* color = [Utils colorWithREGHex:0x00FF00 alpha:1];

 

반응형