按下时UIAlertAction标题颜色已更改。怎么解决?

时间:2015-10-23 12:23:54

标签: objective-c ios9 uialertaction

我想更改UIAlertAction的标题颜色。现在我正在使用iOS 9.我正在使用以下代码。当我按下“取消”按钮时,其颜色发生了变化。

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"My Title" preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"CANCEL" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){

    [self performSelector:@selector(cancelCliked:) withObject:nil];

}]];
[alertController addAction:[UIAlertAction actionWithTitle:@"ASSIGN" style:UIAlertActionStyleDefault handler:nil]];

NSMutableAttributedString *attributedstring = [[NSMutableAttributedString alloc]initWithString:@"My Title"];
[attributedstring addAttribute:NSForegroundColorAttributeName value:[UIColor vsBlueColor] range:NSMakeRange(0, 8)];
[alertController setValue:attributedstring forKey:@"attributedMessage"];
alertController.view.tintColor = [UIColor orangeColor];
[alertController addTextFieldWithConfigurationHandler:^(UITextField *textField) {

    textField.placeholder = @"Enter text:";
    textField.borderStyle = UITextBorderStyleNone;
    textField.tintColor = [UIColor orangeColor];

}];
[self presentViewController:alertController animated:YES completion:nil];

 -(void)cancelCliked:(id)sender{

UIButton *button = (UIButton *)sender;
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
}

0 个答案:

没有答案