HelloWorld HelloWorld - 6 months ago 23
Swift Question

How can I change UIButton title color?

I create a button programmatically

button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchDown];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];


how can I change title color?

Answer

You can use -[UIButton setTitleColor:forState:] to do this.

Example:

buttonName setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

Thanks to richardchildan

Comments