user1120133
user1120133

Reputation: 3234

UIButton color change

I want to change UIButton color from brown color to darkbrown color. How i can do that

myButton.backgroundColor = [UIColor brownColor];

Any ideas that how to change this brown color to darkbrown color.

Thanks for help.

Upvotes: 1

Views: 1295

Answers (3)

rob mayoff
rob mayoff

Reputation: 385988

If you just want a darker brown specifically, you can manually specify it:

myButton.backgroundColor = [UIColor colorWithHue:1.0/12 saturation:2.0/3 brightness:4.0/10 alpha:1];

(The default brown color has brightness 6.0/10.)

If you want to be able to darken a color in general, you can do it like this:

UIColor *color = UIColor.brownColor;
CGFloat hue, saturation, brightness, alpha;
[color getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
brightness *= .8;
UIColor *darkerColor = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:alpha];

Upvotes: 2

Code Slinger
Code Slinger

Reputation: 1130

There's no darkBrownColor predefined, but you can create a UIColor with RGB values like so:

UIColor *myColor = [UIColor colorWithRed:0.5f green:0.5f blue:0.5f alpha:1.0f];

Upvotes: 1

Kobski
Kobski

Reputation: 1636

Starting on iOS 5 there is a property called tintColor.

@property(nonatomic,retain) UIColor *tintColor

Upvotes: 1

Related Questions