zeeple
zeeple

Reputation: 5617

What color is the text of a default UIButton?

What color is the text of a default UIButton? I am trying o recreate it in some table view cells but not having luck. The closest I have come is:

[UIColor colorWithRed:0/255.0 green:51.0/255.0 blue:102.0/255.0 alpha:1];

Is that color, font size and style documented anywhere?

Upvotes: 2

Views: 11741

Answers (5)

Stefan Arentz
Stefan Arentz

Reputation: 34935

This is a pretty old question but I thought I would add my own answer anyway.

If you need a custom 'text only' button on iOS 7 and up that has the same color then do not create it with UIButton() but with UIButton.buttonWithType(UIButtonType.System).

That will give you a text button with the same properties as a standard system button, including the correct color. You can then use this button as a template and change things like the font size or add an image, etc.

Upvotes: 13

Timm Liberty
Timm Liberty

Reputation: 11

Personally what I would do is capture the color of the text in viewDidLoad using the property currentTitleColor and then use that when needed. That way you don't have to worry about rgb and the rest.

So in the interface set up a UIColor property and Outlet for your button

@property (strong,nonatomic)UIColor *backToTheDefaultTextColor;
@property (weak, nonatomic) IBOutlet UIButton *myButton;

In viewDidLoad get the buttons title color with

_backToTheDefaultTextColor = _myButton.currentTitleColor;

Then after you have changed the color of the title of the button and want to revert back simply put

_myButton.titleLabel.textColor = _backToTheDefaultColor;

Upvotes: 1

Toastor
Toastor

Reputation: 8990

Try the following:

CGFloat red;
CGFloat green;
CGFloat blue;
CGFloat alpha;

UILabel *buttonLabel = [yourButton titleLabel];
UIColor *textColor = [buttonLabel textColor];

[textColor getRed:&red green:&green blue:&blue alpha:&alpha];

Now red, green, blue and alpha will contain the values you're looking for:

NSLog(@"Red: %f Green:%f Blue:%f Alpha:%f", red, green, blue, alpha);

For iOS 6 this will return:

Red:0.220000 Green:0.330000 Blue:0.530000 Alpha:1.000000

Upvotes: 5

virindh
virindh

Reputation: 3765

  1. Run a sample app with a UIButton on the simulator
  2. Use spotlight to search for 'DigitalColor Meter'(with out the quotes, see below) enter image description here
  3. Use the pointer to point it at the text color, this will give you the RGB Value of the text
  4. The font size and other values can be found using IB.

Upvotes: 7

ChrisBob
ChrisBob

Reputation: 338

Text Color to Match Default UIButton Color [Blue]

It looks like someone pulled it out programmatically, but I have not confirmed it.

Upvotes: 1

Related Questions