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];

视图如下

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容