此文学习来源为: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:警告对话框和等待提示器的更多相关文章

  1. IOS开发之XCode学习009:UIViewController使用

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 通过点击屏幕事件,调用ViewController ...

  2. IOS开发之XCode学习008:UIViewController基础

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 红色框选部分用A代替,AppDelegate类在程序框架启动时,如果在i ...

  3. IOS开发之XCode学习011:UISwitch控件

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.定义UIswitch控件,添加UIswitc ...

  4. IOS开发之XCode学习007:UIWindow对象

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm #import "AppDelegate.h" @i ...

  5. IOS开发之XCode学习012:Slider和ProgressView

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.定义UISlider和UIProgressV ...

  6. IOS开发之XCode学习010:定时器和视图对象

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能: 1.通过点击"启动定时器"按钮 ...

  7. IOS开发之XCode学习013:步进器和分栏控件

    此文学习来源为:http://study.163.com/course/introduction/1002858003.htm 此工程文件实现功能:  1.定义UIStepper和UISegmente ...

  8. iOS开发之Xcode常用调试技巧总结

    转载自:iOS开发之Xcode常用调试技巧总结 最近在面试,面试过程中问到了一些Xcode常用的调试技巧问题.平常开发过程中用的还挺顺手的,但你要突然让我说,确实一脸懵逼.Debug的技巧很多,比如最 ...

  9. iOS开发之XCode设置--消除AFN的警告

    本篇是直接拷贝别人的博文,地址:http://blog.csdn.net/liyiyismile/article/details/50434844 在项目开发中导入第三方sdk后会提示很多这样的错误: ...

随机推荐

  1. STM32F4 输入输出(GPIO)模式理解

    stm32的GPIO的配置模式有好几种,包括: 1. 模拟输入: 2. 浮空输入: 3. 上拉输入: 4. 下拉输入: 5. 开漏输出: 6. 推挽输出: 7. 复用开漏输出: 8. 复用推挽输出   ...

  2. cookie的设置和获取

    // 创建cookiefunction setCookie(name, value, expires, path, domain, secure) { var cookieText = encodeU ...

  3. idea好用插件(一)

    代码规范插件 Alibaba Java Coding Guidelines 安装后 可以在文件.文件夹邮件,显示编码规约扫描,点击后显示 可以通过双击定位问题代码,对某些问题可以进行快速的修复 比如: ...

  4. hdu5788 level up

    贴下以前写的代码 比赛前我准备着重看的 主席树 树dp 字符串 #include<bits/stdc++.h> using namespace std; typedef long long ...

  5. Text Document Analysis CodeForces - 723B

    Modern text editors usually show some information regarding the document being edited. For example, ...

  6. Drying POJ - 3104

    It is very hard to wash and especially to dry clothes in winter. But Jane is a very smart girl. She ...

  7. 移动端开发底部元素margin-bottom失效解决办法

    一.情景 记得之前开发一个微信端页面时,发现页面底部元素margin-bottom在ios下失效,在安卓内正常...... 1.safari浏览器内页面底部元素设置margin-bottom失效: 2 ...

  8. Python网络爬虫 | Scrapy爬取妹子图网站全站照片

    根据现有的知识,写了一个下载妹子图(meizitu.com)Scrapy脚本,把全站两万多张照片下载到了本地. 网站的分析 网页的网址分析 打开网站,发现网页的网址都是以 http://www.mei ...

  9. Apace Ignite剖析

    1.概述 Apache Ignite和Apache Arrow很类似,属于大数据范畴中的内存分布式管理系统.在<Apache Arrow 内存数据>中介绍了Arrow的相关内容,它统一了大 ...

  10. 【BZOJ1968】约数研究(数论)

    [BZOJ1968]约数研究(数论) 题面 BZOJ链接(题目是图片形式的) 题解 傻逼题 \(NOIP\) \(T1\)难度 不会做的话您可以退役 #include<iostream> ...