IOS开发之XCode学习014:警告对话框和等待提示器
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm
此工程文件实现功能:
1、警告对话框和等待提示器的概念
2、警告对话框和等待提示器的属性
3、警告对话框和等待提示器的使用
===========================ViewController.h脚本==============================
@interface ViewController : UIViewController <UIAlertViewDelegate>
{
//定义一个警告对话框视图对象
UIAlertView* _alertView;
//等待提示对象
//当下载或加载比较大的文件时,可以显示此控件,处于提示等待状态
UIActivityIndicatorView* _activityIndicatorView;
}
@property (retain,nonatomic) UIAlertView* alertView;
@property (retain,nonatomic) UIActivityIndicatorView * activityIndicatorView;
@end
===========================ViewController.m脚本==============================
@interface ViewController ()
@end
@implementation ViewController
//属性和成员变量的同步
@synthesize alertView = _alertView;
@synthesize activityIndicatorView = _activityIndicatorView;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
for (int i = 0; i < 2; i++) {
UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
btn.frame = CGRectMake(100, 100 + 100 * i, 100, 40);
if (i == 0) {
[btn setTitle:@"警告对话框" forState:UIControlStateNormal];
}
else if (i == 1)
{
[btn setTitle:@"等待指示器" forState:UIControlStateNormal];
}
btn.tag = 101 + i;
[btn addTarget:self action:@selector(pressBtn:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
}
- (void) pressBtn:(UIButton*) btn
{
//警告对话框
if (btn.tag == 101) {
//创建警告对话框
//P1:对话框标题
//P2:提示信息
//P3:处理按钮事件的代理对象
//P4:取消按钮的文字
//P5:其他按钮文字
//P6....:添加其他按钮
//PLast:表示按钮添加结束
//两个按钮横着排,多个竖着排
_alertView = [[UIAlertView alloc] initWithTitle:@"警告"
message:@"你的手机电量过低,即将关机,请保存好数据"
delegate:self
cancelButtonTitle:@"取消" //取消按钮永远放最后
otherButtonTitles:@"OK",@"11",@"22", nil];
//显示对话框
[_alertView show];
}
//创建等待提示器
else if (btn.tag == 102)
{
//宽度和高度不可变更
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(100, 300, 80, 80)];
//设定提示的风格:小灰,小白,大白
_activityIndicatorView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;//UIActivityIndicatorViewStyleWhite;//UIActivityIndicatorViewStyleGray;
self.view.backgroundColor = [UIColor blackColor];
[self.view addSubview:_activityIndicatorView];
//启动动画并显示
[_activityIndicatorView startAnimating];
//停止等待动画并隐藏
//[_activityIndicatorView stopAnimating];
}
}
//当点击对话框的按钮时,调用此函数
//P1:对话框对象本身
//P2:按钮的索引
- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"index = %ld\n",buttonIndex);
}
//对话框即将消失,此函数被调用
- (void) alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"即将消失");
}
//对话框已经消失,此函数被调用
- (void) alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSLog(@"对话框已经消失");
}
程序运行结果:
按钮
警告对话框(2个按钮:横排)
警告对话框(4个按钮:竖排)
等待指示器:(大白风格)
学习总结:
- 重点:警告对话框和等待提示器的概念
- 难点:警告对话框和等待提示器的用法
源码链接地址:https://pan.baidu.com/s/1yrOLXZZeu9MiOWtMq5-EGA 密码:7t1l
IOS开发之XCode学习014:警告对话框和等待提示器的更多相关文章
- IOS开发之XCode学习009:UIViewController使用
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 通过点击屏幕事件,调用ViewController ...
- IOS开发之XCode学习008:UIViewController基础
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 红色框选部分用A代替,AppDelegate类在程序框架启动时,如果在i ...
- IOS开发之XCode学习011:UISwitch控件
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.定义UIswitch控件,添加UIswitc ...
- IOS开发之XCode学习007:UIWindow对象
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm #import "AppDelegate.h" @i ...
- IOS开发之XCode学习012:Slider和ProgressView
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.定义UISlider和UIProgressV ...
- IOS开发之XCode学习010:定时器和视图对象
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.通过点击"启动定时器"按钮 ...
- IOS开发之XCode学习013:步进器和分栏控件
此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.定义UIStepper和UISegmente ...
- iOS开发之Xcode常用调试技巧总结
转载自:iOS开发之Xcode常用调试技巧总结 最近在面试,面试过程中问到了一些Xcode常用的调试技巧问题.平常开发过程中用的还挺顺手的,但你要突然让我说,确实一脸懵逼.Debug的技巧很多,比如最 ...
- iOS开发之XCode设置--消除AFN的警告
本篇是直接拷贝别人的博文,地址:http://blog.csdn.net/liyiyismile/article/details/50434844 在项目开发中导入第三方sdk后会提示很多这样的错误: ...
随机推荐
- eclipse Maven配置
①下载:http://maven.apache.org/download.cgi ②解压至:F:\Study\apache-maven-3.5.2 ③配置环境变量 变量名:M2_HOME 变量值:F: ...
- 利用js实现placeholder占位符,甩开ie不兼容
正常的写法 <input type="text" placeholder="占位符"> 这种写法ie低版本的支持不友好,为了满足某些测试或者产品的变 ...
- find命令 参数
记一下我遇到过的: 中 !表示否定 -a 表示并且 -o 或者 perm注意权限模式,有无 -,单表含义不同,有-是表示属主.组.其他组权限对应(即某位为0时,表示不指定要匹配的权限,而不是没有 ...
- GetWindowRect、GetClientRect、ScreenToClient与ClientToScreen
GetWindowRect是取得窗口在屏幕坐标系下的RECT坐标(包括客户区和非客户区),这样可以得到窗口的大小和相对屏幕左上角(0,0)的位置. GetClientRect取得窗口客户区(不包括非客 ...
- R语言与格式、日期格式、格式转化
每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- R语言的基础包中提供了两种类型的时间数据,一类 ...
- Python 文件的输入与输出
1. 文本文件的读写主要通过open()所构建的文件对象来实现.我们打开一个文件,并使用一个对象来表示该文件 , f = open(d,r) 其中d是文件名,r是模式 "r" 文件 ...
- hibernate学习(四)hibernate的一级缓存&快照
缓存:提高效率 硬件的 CPU缓存 硬盘缓存 内存 软件的 io流缓存 hibernate 的一级缓存 也是为了操作数据库的效率. 证明一级缓存在 : Person p=sessio ...
- 使用pyh生成HTML文档
title: 使用pyh生成HTML文档 tags: [python3, 爬虫,pyh] date: 2018-03-09 21:01:34 categories: Python keywords: ...
- PHP 数组模糊查询
function search() { $a=array( '0' => array('id'=>1,'pid'=>0,'name'=>'水果'), '1' => arr ...
- ssm整合快速入门程序(三)之Data类型转换器
今天就写写springmvc配置Data类型转换器 首先在创建一个转换器的包cn.my.ssm.controller.converter,创建一个CustomDateConverter类实现Conve ...