三种弹窗的解析
2016-01-22 23:28
267 查看
1.第一种弹窗(分全系统和IOS8以上系统的两种做法)
![](http://img.blog.csdn.net/20160122232456031?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
UIAlertView
这种方法要添加上委托UIAlertViewDelegate
[/code]
需要更多的按钮只需要在“确定”的后面添加 @"第三个按钮"依次类推即可。
一般写法
[/code]
委托的监听方法
[/code]
无论跳出来的弹窗是一个按键,还是几个按键,buttonIndex的值按实例时添加按钮的顺序从0逐渐加1.(以后再说,马上升级,取消)。
如果你按以上的做法xcode会提示你warning。理由是不赞成你用这些老方法提倡使用
UIAlertController
[/code]
第二种(一般建议在重要的数据增删二次确认中使用)
![](http://img.blog.csdn.net/20160122232437510?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
[/code]
监听方法
[/code]
第三种
通常用在点击下载或者无足轻重的消息提示上。
[/code]
![](http://img.blog.csdn.net/20160122232525354?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
同时结合 alpha,动画,最后利用
[/code]
删除 就能做出一个漂亮的弹窗了
UIAlertView
这种方法要添加上委托UIAlertViewDelegate
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"提示内容" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[/code]
需要更多的按钮只需要在“确定”的后面添加 @"第三个按钮"依次类推即可。
一般写法
-(void)autoupgrade
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"版本更新" message:@"有新版本发布,是否立即升级?" delegate:self cancelButtonTitle:@"以后再说" otherButtonTitles:@"马上升级",@"取消", nil];
alert.tag = 1; //给定一个值方便在多个UIAlertView时能进行分辨
[alert show];//让弹窗显示出来
}
[/code]
委托的监听方法
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if(buttonIndex == 1){
if(alertView.tag == 1){//tag就是专门拿来分辨的
//[[NSNotificationCenter defaultCenter] postNotificationName:@"theLeftDot" object:nil];
NSLog(@"tag为1的alert");
}
}
}
[/code]
无论跳出来的弹窗是一个按键,还是几个按键,buttonIndex的值按实例时添加按钮的顺序从0逐渐加1.(以后再说,马上升级,取消)。
如果你按以上的做法xcode会提示你warning。理由是不赞成你用这些老方法提倡使用
UIAlertController
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"版本更新" message:@"有新版本发布,是否立即升级?" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){NSLog(@"");}];
UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:cancelAction];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
[/code]
第二种(一般建议在重要的数据增删二次确认中使用)
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"更新提示" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"其他", nil];
[sheet showInView:self.view];
[/code]
监听方法
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
[/code]
第三种
通常用在点击下载或者无足轻重的消息提示上。
UILabel *label = [[UILabel alloc] init];
label.text = [NSString stringWithFormat:@"成功下载"];
label.font = [UIFont systemFontOfSize:12];
label.textAlignment = NSTextAlignmentCenter;//文本居中
label.textColor = [UIColor whiteColor];
label.backgroundColor = [UIColor blackColor];
label.frame = CGRectMake(0, 0, 150, 25);
label.center = CGPointMake(160, 240);
//设置圆角,大多数圆角或者圆形提示弹窗都能利用这个修出来
label.layer.cornerRadius = 5;
//圆角的显示
label.clipsToBounds = YES;
or
label.layer.masksToBounds = YES; //因为ios7之后默认为no
[self.view addSubview:label];
[/code]
同时结合 alpha,动画,最后利用
[label removeFromSuperview]
[/code]
删除 就能做出一个漂亮的弹窗了
相关文章推荐
- 蓝桥杯 日期计算
- coco2dx-js 实现 层拦截 点击响应事件
- Java集合(实现类线程安全性)
- php 获取自己的公网IP
- “请运行Chkdsk工具”怎么解决
- innerHTML和nnerText造成的乱码现象 以及 background-image放入.css中失效
- UVALive 4225 / HDU 2964 Prime Bases 贪心
- String、StringBuffer和StringBuilder类
- 1204 寻找子串位置
- codeforces 264B
- What are bitwise operators?
- 欢迎使用CSDN-markdown编辑器
- hust oj 安装与升级,以及编译器升级
- UVA 1339 Ancient Cipher【水。。。】
- 蓝桥杯 01背包
- 背包问题(dp基础)
- RunLoop学习
- uva10625 Undraw the Trees
- Eclipse Tomcat配置
- 算法-蓝桥杯习题(3-4)