弹窗提醒的实现

UIAlertController

  1. 实例化方法

title : 一般设置为需要显示的弹窗消息

message : title下面显示的字体较小的信息,一般为nil

UIAlertControllerStyle : 弹窗展示的样式,actionSheet表示底部弹出的弹窗,alert表示中间弹出的弹窗


[UIAlertController alertControllerWithTitle:<#(nullable NSString *)#> message:<#(nullable NSString *)#>preferredStyle:<#(UIAlertControllerStyle)#>];

复制代码
  1. 添加控件

UIAlertAction 是UIAlertController的子控件,为UIAlertController实现按钮点击功能

title : 表示点击按钮的文字

style : 表示点击按钮的样式,注意在同一个AlertController中只允许同时存在一个cancel,否则程序会报错

handler : 点击按钮时执行的代码块


[UIAlertActionaction WithTitle:<#(nullable NSString *)#> style:<#(UIAlertActionStyle)#>handler:<#^(UIAlertAction * _Nonnull action)handler#>]

复制代码
  1. 展示弹窗

self : 当前控制器

controller : 要显示的弹窗对象

animated : 是否带有动画效果

completion : block代码块,一般传nil


[self presentViewController:<#(nonnull UIViewController *)#> animated:<#(BOOL)#>completion:<#^(void)completion#>]

复制代码

被废弃的UIAlertView


- (void) show {

      UIAlertView*alertView =[[UIAlertView alloc] initWithTitle:@"warning"message:@""delegate:nilcancelButtonTitle:@"cancel"otherButtonTitles:@"sure",nil];    

     [alertView show];

}

复制代码

转载于:https://juejin.im/post/5b96349f6fb9a05cff31f96f

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值