0

我想更改 的标题颜色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];
}
4

0 回答 0