I have a condition in my app where user can choose 3 colors, but those colors should not match with each other, the problem is user can choose the similar color from the pallet for all 3 fields.
I'm trying below code, here color2 has slightly different value of 'green' than color1 :-
UIColor *color1 = [UIColor colorWithRed:1 green:(CGFloat)0.4 blue:1 alpha:1];
UIColor *color2 = [UIColor colorWithRed:1 green:(CGFloat)0.2 blue:1 alpha:1];
if ([color1 isEqual:color2]) {
NSLog(@"equals");
}else {
NSLog(@"not equal");
}
output: 'not equal'
This is correct by logic because it compares RGB value but I want to check range of it, Let me know if anyone knows how to compare the similar colors.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…