三种弹窗的解析
来源:互联网 发布:淘宝网上假发 编辑:程序博客网 时间:2024/05/16 06:02
1.第一种弹窗(分全系统和IOS8以上系统的两种做法)
UIAlertView
这种方法要添加上委托UIAlertViewDelegate
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"提示内容" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
需要更多的按钮只需要在“确定”的后面添加 @"第三个按钮"依次类推即可。
一般写法
-(void)autoupgrade
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"版本更新" message:@"有新版本发布,是否立即升级?" delegate:self cancelButtonTitle:@"以后再说" otherButtonTitles:@"马上升级",@"取消", nil];
alert.tag = 1; //给定一个值方便在多个UIAlertView时能进行分辨
[alert show];//让弹窗显示出来
}
委托的监听方法
-(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");
}
}
}
无论跳出来的弹窗是一个按键,还是几个按键,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];
第二种(一般建议在重要的数据增删二次确认中使用)
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"更新提示" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"确定" otherButtonTitles:@"其他", nil];
[sheet showInView:self.view];
监听方法
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
第三种
通常用在点击下载或者无足轻重的消息提示上。
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];
同时结合 alpha,动画,最后利用
[label removeFromSuperview]
删除 就能做出一个漂亮的弹窗了
0 0
- 三种弹窗的解析
- XML的解析 DOM解析
- XML的两种解析方式逐行解析(SAX解析)节点解析(DOM解析)
- snooper 的概要解析与详细解析
- Oracle的硬解析和软解析
- 解析JS的脚本解析引擎
- Oracle的硬解析和软解析
- Oracle的硬解析和软解析
- dom解析与sax解析的区别
- sax解析和dom解析的区别
- DOM解析与SAX解析的区别
- dom解析和sax解析的特点
- xml文件的解析--libxml库函数解析
- 解析”无法解析的外部符号“
- easyui 的页面解析 parser解析器
- quagga 的原理解析 zebra原理解析
- XML解析的两种解析方式
- pull解析和sax解析的区别
- Eclipse Tomcat配置
- leetcode第17题——**Letter Combinations of a Phone Number
- 欢迎使用CSDN-markdown编辑器
- 1204 寻找子串位置
- cvResize() 图像放缩
- 三种弹窗的解析
- codeforces 264B
- What are bitwise operators?
- String、StringBuffer和StringBuilder类
- innerHTML和innerText造成的乱码现象 以及 background-image放入.css中失效
- 蓝桥杯 日期计算
- Java集合(实现类线程安全性)
- codeforces 258B
- 值得 Web 开发人员学习的20个 jQuery 实例教程