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后会提示很多这样的错误: ...
随机推荐
- 看eShopOnContainers学一个EventBus
最近在看微软eShopOnContainers 项目,看到EventBus觉得不错,和大家分享一下 看完此文你将获得什么? eShop中是如何设计事件总线的 实现一个InMemory事件总线eShop ...
- Redis笔记5-redis高可用方案
一.哨兵机制 有了主从复制的实现以后,如果想对主服务器进行监控,那么在redis2.6以后提供了一个"哨兵"的机制.顾名思义,哨兵的含义就是监控redis系统的运行状态.可以启动多 ...
- iOS.Animations.by.Tutorials.v2.0汉化
翻译自:iOS.Animations.by.Tutorials.v2.0 前五章将向你介绍动画API-UIKit框架.这个API是专门设计来帮助你轻松轻而易举的为视图控件赋予生命,同时避免了核心动画的 ...
- 如何编译linux第一个模块 hellomod.ko
Linux下的驱动程序也没有听上去的那么难实现,我们可以看一下helloworld这个例子就完全可以了解它的编写的方式! 我们还是先看一个这个例子,helloworld 1. [代码]hellowor ...
- [php错误]PHP中Notice: unserialize(): Error at offset of bytes in on line 的解决方法
使用unserialize函数将数据储存到数据库的时候遇到了这个报错, 后来发现是将gb2312转换成utf-8格式之后, 每个中文的字节数从2个增加到3个之后导致了反序列化的时候判断字符长度出现了问 ...
- SQL注入攻击三部曲之进阶篇
SQL注入攻击三部曲之进阶篇 通过入门篇的学习,我们知道了SQL注入攻击的判断方法,但是如果想侵入网站,获取网站的机密内容,那么仅靠入门篇的知识是无法达到的.本篇文章我们将进一步的分析SQL注入攻击. ...
- 嵌入式linux------ffmpeg移植 解码H264(am335x解码H264到yuv420并通过SDL显示)
/* 编译命令:arm-linux-gcc -o show2642 264showyuv2.c -I/usr/local/ffmpeg_arm/include/ -L/usr/local/ffmpeg ...
- 错误代码: 1045 Access denied for user 'skyusers'@'%' (using password: YES)
1. 错误描述 GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "."; 1 queries exe ...
- java.lang.NoClassDefFoundError: org/apache/jsp/jsp/Container_jsp
1.错误描述 八月 20, 2014 7:10:18 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.servi ...
- Django学习-22-Form
Form是Django的功能较强的验证组件,负责各种表单验证 input中的name属性值要和form中的字段名相同 from django import forms from django.form ...