ios之UIActivityIndicatorView
UIActivityIndicatorView和UIProgressView都继承自UIView,所以他们可以附属在其他视图上。UIActivityIndicatorView是一个进度提示器,显示一个小圆圈在转动,主要用在一些耗时操作的提示上,比如网络请求;UIProgressView是一个进度提示条,不过它可以显示一个进度,可以告知用户操作已经进行了多少,这二者的目的都是为了在应用程序有耗时操作时在UI上进行显示,提高用户体验。
下面分别来创建这个两个控件:
首先在ViewController.h中声明代码:
- #import <UIKit/UIKit.h>
- @interface ViewController : UIViewController
- @property(retain,nonatomic) UIActivityIndicatorView *activityIndicator;
- @property(retain,nonatomic) UIProgressView *progressView;
- - (IBAction)startIndicator:(id)sender;
- - (IBAction)startProgress:(id)sender;
- - (IBAction)startNetWork:(id)sender;
- @end
然后修改ViewController.m文件,具体的解释都在注释里面
- #import "ViewController.h"
- @interfaceViewController ()
- @end
- @implementation ViewController
- @synthesize activityIndicator = _activityIndicator;
- @synthesize progressView = _progressView;
- - (void)viewDidLoad
- {
- [superviewDidLoad];
- }
- - (IBAction)startIndicator:(id)sender {
- //初始化指示器
- self.activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(140, 200, 30, 30)];
- /*
- 指定指示器的类型
- 一共有三种类型:
- UIActivityIndicatorViewStyleWhiteLarge //大型白色指示器
- UIActivityIndicatorViewStyleWhite //标准尺寸白色指示器
- UIActivityIndicatorViewStyleGray //灰色指示器,用于白色背景
- */
- self.activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
- //停止后是否隐藏(默认为YES)
- self.activityIndicator.hidesWhenStopped = YES;
- //将Indicator添加到视图中
- [self.viewaddSubview:self.activityIndicator];
- //开始转动
- [self.activityIndicator startAnimating];
- //操作队列
- NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init];
- //设置最大的操作数
- [operationQueue setMaxConcurrentOperationCount:1];
- //构建一个操作对象,selector指定的方法是在另外一个线程中运行的
- NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self
- selector:@selector(runIndicator) object:nil];
- //将操作加入队列,此时后台线程开始执行
- [operationQueue addOperation:operation];
- }
- - (IBAction)startProgress:(id)sender {
- self.progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(70, 260, 180, 20)];
- /*
- 设置风格属性
- 有两种风格属性:
- UIProgressViewStyleDefault
- UIProgressViewStyleBar
- */
- self.progressView.progressViewStyle = UIProgressViewStyleDefault;
- //设置进度,值为0——1.0的浮点数
- // self.progressView.progress = .5;
- [self.viewaddSubview:self.progressView];
- //设定计时器,每隔1s调用一次runProgress方法
- [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(runProgress) userInfo:nil repeats:YES];
- }
- //在状态栏显示有网络请求的提示器
- - (IBAction)startNetWork:(id)sender {
- UIApplication *app = [UIApplication sharedApplication];
- if (app.isNetworkActivityIndicatorVisible) {
- app.networkActivityIndicatorVisible = NO;
- }else {
- app.networkActivityIndicatorVisible = YES;
- }
- }
- -(void)runIndicator
- {
- //开启线程并睡眠三秒钟
- [NSThread sleepForTimeInterval:3];
- //停止UIActivityIndicatorView
- [self.activityIndicator stopAnimating];
- }
- //增加progressView的进度
- -(void)runProgress
- {
- self.progressView.progress += .1;
- }
- - (void)viewDidUnload
- {
- [superviewDidUnload];
- // Release any retained subviews of the main view.
- [self.activityIndicator release];
- [self.progressView release];
- }
- @end
编译运行后效果如下:
ios之UIActivityIndicatorView的更多相关文章
- iOS开发-UIActivityIndicatorView简单使用
软件开发的时候经常会遇到半天才加载出来数据的情况,不管是程序写的烂,还是说本来网速比较慢,一般都都会给个提示让用户感觉到我们在努力的加载数据,iOS可以通过UIActivityIndicatorVie ...
- iOS - UI - UIActivityIndicatorView
1.UIActivityIndicatorView HUD 指示器 UIActivityIndicatorView * indicatorView = [[UIActivityIndicatorVie ...
- [New learn] UIKit 框架类
NSObject NSObject is the root class of most Objective-C class hierarchies. NSDataAsset The NSDataAss ...
- iOS UIActivityIndicatorView 的使用
UIActivityIndicatorView 非常简单 ,就是一个转圈圈的控件:http://blog.csdn.net/zhaopenghhhhhh/article/details/1209265 ...
- iOS UIActivityIndicatorView
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle ...
- IOS开发UI基础UIActivityIndicatorView的属性
UIActivityIndicatorView 1.activityIndicatorViewStyle设置指示器的样式UIActivityIndicatorViewStyleWhiteLarge U ...
- iOS开发——UI篇Swift篇&UIActivityIndicatorView
UIActivityIndicatorView override func viewDidLoad() { super.viewDidLoad() titleLabel.text = titleStr ...
- IOS UIActivityIndicatorView 等待指示器
自己做的一个 等待指示器 #import <UIKit/UIKit.h> @interface RockIndicatorView : UIView { } @property(nonat ...
- 转 UIActivityIndicatorView、UIProgressView 活动与进度指示器-IOS开发
活动指示器(UIActivityIndicatorView)可以告知用户有一个操作正在进行中.进度指示器(UIProgressView )也具有同样功能,而且还可以告知用户离操作结束还多远. 这两个指 ...
随机推荐
- Label-Free Proteomic Analysis of Exosomes Secreted from THP-1- Derived Macrophages Treated with IFN‑α Identifies Antiviral Proteins Enriched in Exosomes (文献分享一组-张霞)
文献名:Label-Free Proteomic Analysis of Exosomes Secreted from THP-1- Derived Macrophages Treated with ...
- iOS 7:漫谈#define 宏定义(转)
iOS :漫谈#define 宏定义 #define宏定义在C系开发中可以说占有举足轻重的作用.底层框架自不必说,为了编译优化和方便,以及跨平台能力,宏被大量使用,可以说底层开发离开define将寸步 ...
- UWP Popup 弹出提示框
一:需求 做一个类似于安卓的弹出消息框,如图.当用户点击下载或者选择时,能够从底部弹出一个提示框,用于提示用户. 二:Popup 类 不需要我们自己额外去写一个弹窗类,微软自己有一个Popup 弹窗类 ...
- POJ-1258-Agri Ned
链接:https://vjudge.net/problem/POJ-1258#author=fuxianda 题意: 有n个农场,已知这n个农场都互相相通,有一定的距离,现在每个农场需要装光纤,问怎么 ...
- dubbo-spring
一.需求 某个电商系统,订单服务需要调用用户服务获取某个用户的所有地址:创建两个服务模块进行测试 测试预期结果:订单服务web模块在A服务器,用户服务模块在B服务器,A可以远程调用B的功能. 二.工程 ...
- 一个页面有相同ID元素的情况分析
经常会遇到一个页面中有相同定义相同id的情况,从道理上来说,id应该是这个页面中某个元素的唯一标识,所以不应该出现有相同id的情况,否则会产生意想不到的结果.而且各个浏览器的表现也是不一样的.我只做了 ...
- asp.net中,跳转页面的几种方式
js方式的页面跳转1.window.location.href方式 <script language="javascript" type="text/java ...
- spring mvc添加静态资源访问时@Controller无效的解决
web.xml中的url-pattern设置为/,添加mvc:resources访问静态资源时,@Controller无效的问题 web.xml: <servlet> <servle ...
- Vue.js - Day5 - Webpack
在网页中会引用哪些常见的静态资源? JS .js .jsx .coffee .ts(TypeScript 类 C# 语言) CSS .css .less .sass .scss Images .jpg ...
- 从零开始利用vue-cli搭建简单音乐网站(七)
这几天完成了歌曲收藏功能,先看最后效果: 新注册用户:“newuser”,进入“我的音乐界面如下所示” 点击新建歌单,输入:“新歌单”,确认,如下: 目前还没有歌曲,打开音乐界面,点击收藏功能,如下, ...