UIAlertController

官方示例

UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"My Alert"

message:@"This is an alert."

preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault

handler:^(UIAlertAction * action) {}];

[alert addAction:defaultAction];

[self presentViewController:alert animated:YES completion:nil];

实战示例

UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Dont care" message:@"aaaaaa" preferredStyle:UIAlertControllerStyleActionSheet];

NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"Presenting"];

[hogan addAttribute:NSFontAttributeName

value:[UIFont systemFontOfSize:25.0]

range:NSMakeRange(0, 3)];

[alertVC setValue:hogan forKey:@"attributedTitle"];

UIAlertAction *button = [UIAlertAction actionWithTitle:@"Label text"

style:UIAlertActionStyleDefault

handler:^(UIAlertAction *action){

//add code to make something happen once tapped

}];

UIImage *accessoryImage = [UIImage imageNamed:@"someImage"];

[button setValue:accessoryImage forKey:@"image"];

[alertVC addAction:button];

[self presentViewController:alertVC animated:YES completion:nil];

视图如下

UIAlertController_第1张图片

你可能感兴趣的:(UIAlertController)