我已经在移动开发方面做了很多事情,我自己搞清楚事情,但是我很难搞清楚这个......
我正在使用此宏将Android color(packed int)转换为UIColor:
#define ANDROID_COLOR(c) [UIColor colorWithRed:((c>>16)&0xFF)/255.0 green:((c>>8)&0xFF)/255.0 blue:((c)&0xFF)/255.0 alpha:((c>>24)&0xFF)/255.0]
但是我还需要将UIColor转换为Android颜色。很感谢任何形式的帮助!
答案 0 :(得分:8)
这样的事情(未经测试)应该有效:
UIColor *color = // your color
CGFloat red, green, blue, alpha;
if (![color getRed:&red green:&green blue:&blue alpha:&alpha]) {
CGFloat white;
if ([color getWhite:&white alpha:&alpha]) {
red = green = blue = white;
} else {
NSLog(@"Uh oh, not RGB or greyscale");
}
}
long r = red * 255;
long g = green * 255;
long b = blue * 255;
long a = alpha * 255;
long packed_color = (r << 16) | (g << 8) | (b) | (a << 24);
这似乎与你在问题中所表现的相反。