进度环控件 (UIActivityIndicatorView)

进度环控件 (UIActivityIndicatorView)

 

1. 进度环控件 (UIActivityIndicatorView) 属性

  

UIActivityIndicatorView 属性截图 : 

 

 

 

 

(1) Style 属性

 

Style 属性 : 

-- Large White : 大的 白色 风格;

-- White : 白色风格;

-- Gray : 灰色风格;

 

 

 

(2) Color 属性

 

 

Color 属性 : 

-- 作用 : 设置进度条的颜色, 设置该属性会覆盖之前选中的风格中的颜色;

 

 

 

(3) Behavior 属性

 

 

Behavior 属性 

-- Animating : 显示出来后立即转动;

-- Hides When Stopped : 停止时自动隐藏;

 

 

 

(4) UIActivityIndicatorView 大小

 

 

两种大小 : 

-- 标准风格 : 像素值 20 x 20;

-- 大风格 : 像素值 37 x 37;

 

 

 

(5) 控制方法

 

 

UIActivityIndicatorView 控制方法 : 

-- 开始转动 : startAnimating 方法;

-- 停止转动 : stopAnimating 方法;

 

 

 

 

2. UIActivityIndicatorView 代码示例

 

 

 

 

(1) 创建 IBOutletConnection

 

 

创建 IBOutletConnection : 

-- 按住 Option 键 将一个元素拖动到 OCViewController.h 中 : 其中的 Connection 属性, 不要选择 IBOutlet 属性, 选择 IBOutletConnection 属性;

-- 将想要添加到 IBOutletConnection 中的控件拖动到 OCViewController.h 中的 IBOutletConnection 属性变量上 : 

 

 

 

(2) 代码示例

 

 

代码示例 : 

-- 界面设计文件 : 

-- OCViewController.h : 

 

[objc] view plaincopy
 
  1. //  
  2. //  OCViewController.h  
  3. //  UIProgressView  
  4. //  
  5. //  Created by octopus on 15-12-10.  
  6. //  Copyright (c) 2015年 www.octopus.org.cn. All rights reserved.  
  7. //  
  8.   
  9. #import <UIKit/UIKit.h>  
  10.   
  11. @interface OCViewController : UIViewController  
  12.   
  13. @property (strong, nonatomic) IBOutlet UIProgressView *progress1;  
  14. @property (strong, nonatomic) IBOutlet UIProgressView *progress2;  
  15. @property (strong, nonatomic) IBOutlet UIProgressView *progress3;  
  16.   
  17.   
  18. @property (strong, nonatomic) IBOutletCollection(UIActivityIndicatorView) NSArray *IndicatorCollection;  
  19. - (IBAction)start:(id)sender;  
  20. - (IBAction)end:(id)sender;  
  21.   
  22.   
  23. - (IBAction)click:(id)sender;  
  24. @end  



 

-- OCViewController.m 

 

[objc] view plaincopy
 
  1. //  
  2. //  OCViewController.m  
  3. //  UIProgressView  
  4. //  
  5. //  Created by octopus on 15-12-10.  
  6. //  Copyright (c) 2015年 www.octopus.org.cn. All rights reserved.  
  7. //  
  8.   
  9. #import "OCViewController.h"  
  10.   
  11. @interface OCViewController ()  
  12.   
  13. @end  
  14.   
  15. @implementation OCViewController  
  16.   
  17. //定时器  
  18. NSTimer * timer;  
  19. //进度条进度  
  20. CGFloat progress;  
  21.   
  22. /* 
  23.     CGFloat : 是 float 类型, 在 IOS 中定义了下面的类型  
  24.     -- 32 位 : typedef float CGFloat;// 32-bit 
  25.     -- 64 位 : typedef double CGFloat;// 64-bit 
  26.   
  27.     CGPoint : 二维坐标点; 
  28.     -- 定义代码 :  
  29.         struct CGPoint { 
  30.             CGFloat x; 
  31.             CGFloat y; 
  32.         }; 
  33.         typedef struct CGPoint CGPoint; 
  34.   
  35.     CGSize : 矩形的宽度和高度; 
  36.     -- 定义代码 :  
  37.         struct CGSize { 
  38.             CGFloat width; 
  39.             CGFloat height; 
  40.         }; 
  41.         typedef struct CGSize CGSize; 
  42.   
  43.     CGRect : 矩形的位置和大小; 
  44.     -- 定义代码 :  
  45.         struct CGRect { 
  46.             CGPoint origin; 
  47.             CGSize size; 
  48.         }; 
  49.         typedef struct CGRect CGRect; 
  50.  */  
  51.   
  52. - (void)viewDidLoad  
  53. {  
  54.     [super viewDidLoad];  
  55.     // Do any additional setup after loading the view, typically from a nib.  
  56.       
  57.     //创建 可拉伸的图片, 平铺样式  
  58.     UIImage * trackImage = [[UIImage imageNamed:@"Snip20151210_139.png"] resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeTile];  
  59.     UIImage * progressImage = [[UIImage imageNamed:@"Snip20151210_140.png"] resizableImageWithCapInsets:UIEdgeInsetsZero resizingMode:UIImageResizingModeTile];  
  60.       
  61.     //将可拉伸图片设置给进度条  
  62.     self.progress3.progressImage = progressImage;  
  63.     self.progress3.trackImage = trackImage;  
  64.       
  65. }  
  66.   
  67. - (void)didReceiveMemoryWarning  
  68. {  
  69.     [super didReceiveMemoryWarning];  
  70.     // Dispose of any resources that can be recreated.  
  71. }  
  72.   
  73. - (IBAction)start:(id)sender {  
  74.     for(int i = 0; i < 4; i ++){  
  75.         //从集合中获取 UIActivityIndicatorView 控件并开启动画  
  76.         [[self.IndicatorCollection objectAtIndex:i] startAnimating];  
  77.     }  
  78. }  
  79.   
  80. - (IBAction)end:(id)sender {  
  81.     for(int i = 0; i < 4; i ++){  
  82.         //从集合中获取 UIActivityIndicatorView 控件并结束动画  
  83.         [[self.IndicatorCollection objectAtIndex:i] stopAnimating];  
  84.     }  
  85. }  
  86.   
  87. - (IBAction)click:(id)sender {  
  88.     //进度条  
  89.     progress = 0;  
  90.       
  91.     //定时器  
  92.     timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(doProgress) userInfo:nil repeats:YES];  
  93.       
  94. }  
  95.   
  96. - (void) doProgress{  
  97.     progress += 0.1;  
  98.     if(progress > 1.0){  
  99.         [timer invalidate];  
  100.     }else{  
  101.         [self.progress1 setProgress:progress animated:YES];  
  102.         [self.progress2 setProgress:progress animated:YES];  
  103.         [self.progress3 setProgress:progress animated:YES];  
  104.     }  
  105.       
  106.       
  107. }  
  108.   
  109. @end  



 

-- 页面展示效果 : 

 

posted @ 2016-01-07 09:58  sungk  阅读(224)  评论(0编辑  收藏  举报