Hex a UIColor con transparencia
Algoritmo para pasar de Hexadecimal a UIColor un color que tenga transparencia.
- (UIColor *)toUIColor: (NSString *)hex {
unsigned int c;
if ([hex characterAtIndex:0] == '#') {
[[NSScanner scannerWithString:[hex substringFromIndex:1]] scanHexInt:&c];
} else {
[[NSScanner scannerWithString:hex] scanHexInt:&c];
}
float alpha = ((c & 0xff000000) >> 24)/255.0;
if (alpha == 0.0) { //no tiene transparencia
alpha = 1.0;
}
return [UIColor colorWithRed:((c & 0xff0000) >> 16)/255.0 green:((c & 0xff00) >> 8)/255.0 blue:(c & 0xff)/255.0 alpha:alpha];
}
Comentarios
Publicar un comentario