RGriffiths
RGriffiths

Reputation: 5970

UIButton text colour not being set

I have a UIButton that is being created programmatically.

UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(0,0,160, 160)];
[button setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
[button setTitle:@"title" forState:UIControlStateNormal];
button.titleLabel.font = [UIFont fontWithName:@"arial" size:20];
button.titleLabel.textColor = [UIColor colorWithRed:19/255.0f green:73/255.0f blue:17/255.0f alpha:1];

Everything works apart from setting the textColor. Any ideas why?

Upvotes: 0

Views: 57

Answers (2)

plu
plu

Reputation: 1351

[button setTitleColor:[UIColor colorWithRed:19/255.0f green:73/255.0f blue:17/255.0f alpha:1] forState:UIControlStateNormal];

Upvotes: 1

Nookaraju
Nookaraju

Reputation: 1668

try this.

[button.titleLabel setFont:[UIFont fontWithName:@"arial" size:20]];
[button setTitleColor:[UIColor colorWithRed:19/255.0f green:73/255.0f blue:17/255.0f alpha:1] forState:UIControlStateNormal];

Upvotes: 1

Related Questions