-3
正如您從值「val」中看到的那樣,我生成的值是從0到255,那麼如何反轉此浮點值的順序?與浮點值相反的順序
-(UIColor *)colorForIndexToWhite:(NSInteger)index {
NSInteger itemCount = _gradientArrayToWhite.count - 1;
float val = ((float)index/(float)itemCount) * 0.9;
UIColor *colorFromHEXCode = [UIColor colorWithHexString:_hexCode];
NSString *myCount = [NSString stringWithFormat:@"%.f", (colorFromHEXCode.red*255)-(val*255)];
NSLog(@"Red Value: %.f - val: %.f - Result: %@", colorFromHEXCode.red*255, val*255, myCount);
return MP_RGB((colorFromHEXCode.red*255)-(val*255), (colorFromHEXCode.green*255)-(val*255), (colorFromHEXCode.blue*255)-(val*255));
}
This is the Output:
2013-10-02 16:14:02.473 Goolor[993:a0b] Red Value: 70 - val: 0 - Result: 70
2013-10-02 16:14:02.475 Goolor[993:a0b] Red Value: 70 - val: 26 - Result: 44
2013-10-02 16:14:02.475 Goolor[993:a0b] Red Value: 70 - val: 51 - Result: 19
2013-10-02 16:14:02.476 Goolor[993:a0b] Red Value: 70 - val: 76 - Result: -6
2013-10-02 16:14:02.477 Goolor[993:a0b] Red Value: 70 - val: 102 - Result: -32
2013-10-02 16:14:02.478 Goolor[993:a0b] Red Value: 70 - val: 128 - Result: -58
2013-10-02 16:14:02.478 Goolor[993:a0b] Red Value: 70 - val: 153 - Result: -83
2013-10-02 16:14:02.479 Goolor[993:a0b] Red Value: 70 - val: 178 - Result: -108
2013-10-02 16:14:02.480 Goolor[993:a0b] Red Value: 70 - val: 204 - Result: -134
2013-10-02 16:14:02.480 Goolor[993:a0b] Red Value: 70 - val: 230 - Result: -160
Reverse?你的意思是當你得到0時,你想轉換爲255,當你得到255時,你想轉換爲0? – Wain
當x從0變到255時,255-x將從255下降到0。 –
這不是基本上和[你以前的問題]一樣嗎(http://stackoverflow.com/questions/19068294/how-can- I-反向的階的-此浮子值)? –