iOS UIProgressView

#import "ViewController.h"

@interface ViewController ()

{

UIProgressView* progressView1;

UIProgressView* progressView2;

UIProgressView* progressView3;

UIButton *button1;

UIButton *button2;

UIButton *button3;

}

@end

@implementation ViewController

//定义定时器

NSTimer *timer;

CGFloat progval;//定义变量,纪录当前的进度值

- (void)viewDidLoad {

[super viewDidLoad];

progressView1= [[UIProgressView alloc]initWithFrame:CGRectMake(50.0,40.0,200.0,30.0)];

progressView2= [[UIProgressView alloc]initWithFrame:CGRectMake(50.0,120.0,200.0,30.0)];

progressView1.progressViewStyle= UIProgressViewStyleDefault;

progressView2.progressViewStyle= UIProgressViewStyleBar; //设置进度条风格

[self.view addSubview:progressView1];

[self.view addSubview:progressView2];

button1=[[UIButton alloc]initWithFrame:CGRectMake(50, 400, 100, 50)];

[button1 setTitle:@"开始" forState:UIControlStateNormal];

button1.backgroundColor=[UIColor orangeColor];

[button1 addTarget:self action:@selector(aa:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:button1];

button2=[[UIButton alloc]initWithFrame:CGRectMake(180, 400, 100, 50)];

[button2 setTitle:@"停止" forState:UIControlStateNormal];

button2.backgroundColor=[UIColor purpleColor];

[button2 addTarget:self action:@selector(bb:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:button2];

button3=[[UIButton alloc]initWithFrame:CGRectMake(100, 300, 100, 50)];

[button3 setTitle:@"暂停" forState:UIControlStateNormal];

button3.backgroundColor=[UIColor greenColor];

[button3 addTarget:self action:@selector(cc:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:button3];

// Do any additional setup after loading the view, typically from a nib.

}

- (IBAction)aa:(id)sender

{

progval=0;

timer=[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(changeProgress) userInfo:nil repeats:YES];

button1.enabled = NO;

button2.enabled = YES;

}

-(IBAction)bb:(id)sender

{

[timer invalidate];//停用记时器

progressView1.progress=0.0f;

progressView2.progress=0.0f;

button1.enabled = YES;

button2.enabled = NO;

}

-(IBAction)cc:(id)sender

{

[timer invalidate];

button3=[[UIButton alloc]initWithFrame:CGRectMake(100, 300, 100, 50)];

[button3 setTitle:@"重新开始" forState:UIControlStateNormal];

button3.backgroundColor=[UIColor greenColor];

[button3 addTarget:self action:@selector(dd:) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:button3];

}

-(IBAction)dd:(id)sender

{

[button3 setHidden:YES];

timer=[NSTimer scheduledTimerWithTimeInterval:0.2 target:self selector:@selector(changeProgress) userInfo:nil repeats:YES];

}

-(void)changeProgress

{

progval+=0.01;

if (progval>=1.0) {

[timer invalidate];

}

else{

//同时改变进度条的进度值

[progressView1 setProgress:progval animated:YES];

[progressView2 setProgress:progval animated:YES];

}

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

时间: 2024-10-26 22:26:39

iOS UIProgressView的相关文章

从零开始学习IOS(UIProgressView、UIActivitylndicatorView) 属性

//创建进度指示器 UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault]; progressView.frame = CGRectMake(imgView.frame.origin.x, imgView.frame.origin.y+130, 130, 20); //UIProgressViewStyleDefault 标准进度条 /

IOS UIProgressView控件用法

进度条控件是IOS开发中一个简单的系统控件,使用总结如下: 初始化一个进度条: - (instancetype)initWithProgressViewStyle:(UIProgressViewStyle)style; 注意:1.用这个方式初始化的进度条系统会默认给一个长度. 2.进度条的长度可以通过frame来设置,但是只有前三个参数有效. 3.风格枚举如下: typedef NS_ENUM(NSInteger, UIProgressViewStyle) {     UIProgressVie

iOS自定义进度条高度(UIProgressView进度条高度改变的实现)

今天自定义了iOS中的进度条,发现系统的进度条高度无法改变, 现在自己封装了一种进度条(实际是是UIView而不是UIProgressView),可以改变进度条的高度,非常好用,分享给大家,直接上代码: //  CTWBProgress.h //  Created by WBapple on 16/7/31. //  Copyright © 2016年 王彬. All rights reserved. // #import <UIKit/UIKit.h> @interface CTWBProg

【学习ios之路:UI系列】UIProgressView

实现类似读取数据进度条效果 代码如下: ①创建UIProgressView对象 1)定义属性 { NSTimer *_proTimer;//计时 } @property (nonatomic, retain) UIProgressView *proView; //显示进度信息 @property (nonatomic, retain) UILabel *proLabel; @property (nonatomic, assign) float proValue;//保存进度值 //创建控件UIP

IOS基础-UIProgressView

UIProgressView和UIActivityIndicator有些类似 但是不同之处在于, UIProgressView能够更加精确的反应进度 UIActivityIndicator则只能表示事物在进行中 有一个例子是在Mail程序中当在下载信息的时候,有一个UIProgressView显示在底部 - (void)viewDidLoad {     [super viewDidLoad];          //定义一个进度条     UIProgressView *progressV =

UIActivityIndicatorView、UIProgressView 活动与进度指示器-iOS开发

活动指示器(UIActivityIndicatorView)可以告知用户有一个操作正在进行中.进度指示器(UIProgressView )也具有同样功能,而且还可以告知用户离操作结束还多远. 这两个指示器都是派生自UIView,所以他们是视图,也可以附着在视图上. 一.UIActivityIndicatorView 活动指示器 1.创建 UIActivityIndicatorView* activityIndicatorView = [ [ UIActivityIndicatorView  al

iOS开发——UI篇Swift篇&amp;UIProgressView

UIProgressView 1 override func viewDidLoad() { 2 super.viewDidLoad() 3 4 titleLabel.text = titleString 5 6 7 // Do any additional setup after loading the view. 8 9 //创建进度控制器 10 var progressView:UIProgressView = UIProgressView(frame: CGRectMake(20, 10

【iOS开发-10】UIProgressView进度条的几个属性介绍

进度条目前看来不如滑动控件(slider)实用,至少滑动控件可以让用户动,并且我们还能获得滑动控件的值. 目前还未体会到进度条的魅力. - (void)viewDidLoad { //实例化一个进度条,有两种样式,一种是UIProgressViewStyleBar一种是UIProgressViewStyleDefault,几乎无区别 UIProgressView *pro1=[[UIProgressView alloc]initWithProgressViewStyle:UIProgressVi

iOS开发 -文件下载(3 进度条)

一.实现下载文件进度控制 1.代码示例 1 #import "YYViewController.h" 2 3 @interface YYViewController () 4 @property(nonatomic,strong)NSMutableData *fileData; 5 @property(nonatomic,strong)NSFileHandle *writeHandle; 6 @property(nonatomic,assign)long long currentLen