Reputation: 5617
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
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
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
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
Reputation: 3765
Upvotes: 7
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