如何将设计给到的“#xxxxxx”16进制颜色换算成RGB颜色

一般呢美工妹子给到的效果图颜色标记是这个样子的“#xxxxxx”
如何方便我们在代码中使用呢做如下转化

unsigned rafa = 0;
NSString * str = @"#21cbff";
NSScanner * scaner = [NSScanner scannerWithString:str];
[scaner setScanLocation:1];
[scaner scanHexInt:&rafa];
UIColor * color = [UIColor colorWithRed:(( rafa >> 16) & 0xFF)/255.0 green:(( rafa >> 8) & 0x00FF)/255.0 blue:( rafa & 0x0000FF)/255.0 alpha:1.0];
self.view.backgroundColor = color;

推荐阅读更多精彩内容