tôi có một vấn đề trong chuyển đổi UIColor để màu hex, ở đây những gì tôi tìm thấyhex màu từ UIColor
CGColorRef colorref = [[Colorview_ backgroundColor] CGColor];
int numComponents = CGColorGetNumberOfComponents(colorref);
if (numComponents == 4) {
const CGFloat *components = CGColorGetComponents(colorref);
int hexValue = 0xFF0000*components[0] + 0xFF00*components[1] + 0xFF*components[2];
NSString *hexString = [NSString stringWithFormat:@"#%d", hexValue];
}
mã này được đem lại cho tôi # 5.576.149 (ví dụ) cho hexString, chúng tôi thấy có 7 chữ số không 6, nó không phải là một màu hex, bất kỳ trợ giúp sẽ được đánh giá cao, thx.
Bạn có thể sử dụng thư viện này https: // github .com/burhanuddin353/TFTColor –