- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib..
self.view.backgroundColor = [UIColor whiteColor];
UIButton *alertBtn = [UIButton buttonWithType:UIButtonTypeCustom];
alertBtn.backgroundColor = [UIColor redColor];
[alertBtn addTarget:self action:@selector(AlertBtnAtion) forControlEvents:UIControlEventTouchUpInside];
alertBtn.frame = CGRectMake(100, 100, 100, 100);
[self.view addSubview:alertBtn];
}
- (void)AlertBtnAtion
{
UIAlertController *AlertController = [UIAlertController alertControllerWithTitle:@"我有这么多的女朋友 今晚去谁家?" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *Action1 = [UIAlertAction actionWithTitle:@"去小兰家!" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[AlertController dismissViewControllerAnimated:YES completion:nil];
}];
[AlertController addAction:Action1];
UIAlertAction *Action2 = [UIAlertAction actionWithTitle:@"去小红家!" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[AlertController dismissViewControllerAnimated:YES completion:nil];
}];
[AlertController addAction:Action2];
UIAlertAction *Action3 = [UIAlertAction actionWithTitle:@"去小花家!" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[AlertController dismissViewControllerAnimated:YES completion:nil];
}];
[AlertController addAction:Action3];
UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"Default" style:UIAlertActionStyleDefault handler:nil];
[defaultAction setValue:[UIColor blueColor] forKey:@"_titleTextColor"];
[AlertController addAction:defaultAction];
UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"都不见我,还是回家吧!"
style:UIAlertActionStyleCancel
handler:^(UIAlertAction* action)
{
[AlertController dismissViewControllerAnimated: YES completion: nil];
}];
[AlertController addAction:cancel];
//修改title
NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:@"提示"];
[alertControllerStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, 2)];
[alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, 2)];
[AlertController setValue:alertControllerStr forKey:@"attributedTitle"];
//修改message
NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:@"提示内容"];
[alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor greenColor] range:NSMakeRange(0, 4)];
[alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:20] range:NSMakeRange(0, 4)];
[AlertController setValue:alertControllerMessageStr forKey:@"attributedMessage"];
[self presentViewController:AlertController animated:YES completion:nil];
}
@end
网友评论