lenga hao lenga hao - 1 year ago 85
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???


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.