Skip to content

Instantly share code, notes, and snippets.

@Tricertops
Tricertops / UIColor+GuessName.m
Last active August 5, 2020 09:59
UIColor method that approximates human-readable name. Uses no special algorithm, but hard-coded 10 names for 125 colors, defined by my plain sight. No guarantee you will see them the same. Returns one of these: white, blue, purple, red, orange, yellow, green, brown, gray, black.
// The Unlicense (https://unlicense.org)
- (NSString *)guessName {
unsigned char redComponent = roundf(self.redComponent*4);
unsigned char greenComponent = roundf(self.greenComponent*4);
unsigned char blueComponent = roundf(self.blueComponent*4);
// Component methods implemented below.
static NSString * const black = @"black";
static NSString * const red = @"red";