lenga hao lenga hao - 1 year ago 140
iOS Question

UIButton performSelector:withObject:withObject: not making call

here is my code.

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(110, 270, 100, 40);
button.backgroundColor = [UIColor grayColor];
[button setTitle:@"next" forState:UIControlStateNormal];
[self.view addSubview:button];

I want to set button title color through this method
but it doesn't work!

[button performSelector:@selector(setTitleColor:forState:)
withObject:[UIColor blackColor]

Do somebody know why it doesn't work???

Answer Source

Why don't you simply use [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

And in your case

[button performSelector:@selector(setTitleColor:forState:)
             withObject:[UIColor redColor]

Remove @() for UIControlStateNormal.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download