004 在Xcode4.5上创建IOS6.0应用 (等待控件,进度条)

为iOS应用程序开发等待控件

UIActivityIndicatorView

在iOS中开发一个等待控件其实也跟对话框一样特别简单

第一步:把所需要的控件拖入到屏幕当中,如下图



第二步:在ViewController.h文件中加入如下内容,在ViewController.m文件中加入实现方法

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController{
    //定义一个等待控件
    IBOutlet UIActivityIndicatorView * activityIndicatorView;
}

//提供GET SET
@property(nonatomic,retain)UIActivityIndicatorView * activityIndicatorView;

//按钮的点击事件
-(IBAction)prass:(id)sender;

@end

ViewController.m

@implementation ViewController

//实现GET SET
@synthesize activityIndicatorView;


-(IBAction)prass:(id)sender{
    if ([activityIndicatorView isAnimating]) {
        [activityIndicatorView stopAnimating];
    }else{
        [activityIndicatorView startAnimating];
    }
    
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


//消除内存
- (void)dealloc
{
    [activityIndicatorView release];
    [super dealloc];
}
@end

第三步在NIB文件中进行关联

大慨就是按照箭头所指的方向进行关联



就可以实现如下显示的效果



注意:如何让控件在启动的时候不显示,停止的时候消失呢?只有在运行的时候才显示呢?答案很简单只要设置一个属性就行啦



Progress  NSTimer

在iOS中开发一个进度条其实也跟等待一样特别简单

第一步:开发界面



第二步编码

ViewController.h

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController{
    IBOutlet UIProgressView *progressview;
    NSTimer *timer;
}

@property(nonatomic,retain) UIProgressView *progressview;
@property(nonatomic,assign) NSTimer *timer;

-(IBAction)Onclick;

@end

ViewController.m

@implementation ViewController

@synthesize progressview;
@synthesize timer;

-(IBAction)Onclick{
    progressview.progress = 0.0;
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                             target:self
                                           selector:@selector(update)
                                           userInfo:nil
                                            repeats:YES];
    
}


-(void) update{
    progressview.progress +=0.1;
    NSLog(@"%f",progressview.progress);
    if (progressview.progress == 1.0) {
        [timer invalidate];
    }
}


- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    [progressview release];
    [super dealloc];
}

@end

第三步同样跟上面的等待控件一样,进行对界面输入输出。运行结果就是,进度条每一秒钟运行一次,10秒后完成




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shuaiyinoo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值