Created
August 29, 2012 17:20
-
-
Save tewha/3515798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)colors { | |
// Working with colors in Cocoa Touch. | |
// I think almost everyone uses RGB decimal, which is the worst of the ways. You don't have easy control of | |
// brightness, and you've got decimal points in your code that don't map to the way you think of RGB. | |
UIColor *rgbDec = [UIColor colorWithRed:0.484 green:0.745 blue:0.191 alpha:1.000]; | |
// If you're working from 0-255, why not just code that? | |
UIColor *rgbFrac = [UIColor colorWithRed:123.0/255.0 green:190.0/255.0 blue:49.0/255.0 alpha:1.000]; | |
// You could do this with a category, too. | |
UIColor *rgbCustom = [UIColor colorWithRedLevel:123 green:190 blue:49 alpha:1.000]; | |
// A better way is to work with HSB, where you can easily tweak saturation and brightness without affecting hue. | |
UIColor *hsbDec = [UIColor colorWithHue:0.238 saturation:0.682 brightness:0.776 alpha:1.000]; | |
// Still better is to work with HSB in fractions. | |
UIColor *hsbFrac = [UIColor colorWithHue:86.0/360.0 saturation:174.0/255.0 brightness:199.0/255.0f alpha:1.000]; | |
// And, again, you could create your own category | |
UIColor *hsbCustom = [UIColor colorWithHueInDegrees:86 saturation:174 brightness:199 alpha:1.000]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment