views:

613

answers:

1

I want to set the background color of a label using HSV instead of RGB. How do I implement this into code?

Code:

//.m file

#import "IBAppDelegate.h"

@implementation IBAppDelegate


@synthesize label;

{
self.label.backgroundColor = [UIColor colorWithRed:1.0f
                                             green:0.8f
                                              blue:0.0f
                                             alpha:1.0f];
}
+6  A: 

You can use the following convenience constructor of the UIColor object:

+ (UIColor *)colorWithHue:(CGFloat)hue saturation:(CGFloat)saturation brightness:(CGFloat)brightness alpha:(CGFloat)alpha
arul
RGB -> HSV requires some custom code, but HSV -> RGB is pretty easy. You're in luck!
Ben Gotow
Thanks! It didn't know it would be so easy. That specific code actually gave me some syntax errors. It worked out better as: [UIColor colorWithHue:(CGFloat) saturation:(CGFloat) brightness:(CGFloat) alpha:(CGFloat)]
Evelyn
Evelyn: That's because what arul gave you is the method's prototype, not a message expression. It's not supposed to be pasted into a method body.
Peter Hosey