#import "ViewController.h"
@interfaceViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
UIAlertController *alertController = [UIAlertControlleralertControllerWithTitle:@"提示"message:@"提示内容"preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *defaultAction = [UIAlertActionactionWithTitle:@"Default"style:UIAlertActionStyleDefaulthandler:nil];
UIAlertAction *destructiveAction = [UIAlertActionactionWithTitle:@"Destructive"style:UIAlertActionStyleDestructivehandler:nil];
UIAlertAction *cancelAction = [UIAlertActionactionWithTitle:@"Cancel"style:UIAlertActionStyleCancelhandler:nil];
[alertController addAction:defaultAction];
[alertController addAction:destructiveAction];
[alertController addAction:cancelAction];
//修改title
NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedStringalloc] initWithString:@"提示"];
[alertControllerStr addAttribute:NSForegroundColorAttributeNamevalue:[UIColorredColor] range:NSMakeRange(0, 2)];
[alertControllerStr addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:17] range:NSMakeRange(0, 2)];
[alertController setValue:alertControllerStr forKey:@"attributedTitle"];
//修改message
NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedStringalloc] initWithString:@"提示内容"];
[alertControllerMessageStr addAttribute:NSForegroundColorAttributeNamevalue:[UIColorgreenColor] range:NSMakeRange(0, 4)];
[alertControllerMessageStr addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:20] range:NSMakeRange(0, 4)];
[alertController setValue:alertControllerMessageStr forKey:@"attributedMessage"];
//修改按钮
if (![cancelAction valueForKey:@"titleTextColor"]) {
[cancelAction setValue:[UIColorredColor] forKey:@"titleTextColor"];
}
[selfpresentViewController:alertController animated:YEScompletion:nil];
}