UIAlercontroller 警告框

2016-07-15  本文已影响158人  墨凌风起

//alert  标题  提示信息  警告框的形式

```

UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"警告" message:@"提示信息" preferredStyle:UIAlertControllerStyleAlert];

//增加选项1

[alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

//点击确认按钮的事件

NSLog(@"确定键被触发----");

}]];

//增加选项2

[alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {

//        点击取消按钮的事件的

NSLog(@"取消按钮被触发-----");

}]];

//增加输入框

[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {

//可以进行文本框订制信息  后续操作

textField.backgroundColor = [UIColor redColor];

}];

//展现方式

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

//延时2秒后自动消失

[self performSelector:@selector(dismissAlert:) withObject:alert afterDelay:2];

-(void)dismissAlert:(UIAlertController *)alert{

if (alert) {

[alert dismissViewControllerAnimated:YES completion:nil];

}

}

```

/************************页面底部弹框************************

```

UIAlertController * actionSheet = [UIAlertController alertControllerWithTitle:@"分享" message:@"提示" preferredStyle:UIAlertControllerStyleActionSheet];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"新浪微博" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

NSLog(@"分享到新浪微博  ---- ");

}]];

[actionSheet addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]];

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

```

上一篇下一篇

猜你喜欢

热点阅读