iphone常用控件之UIActivityIndicatorView(风火轮)

//先定义一个变量值
BOOL isProgressShow;

-(void)buttonClicked{
    
    if (isProgressShow) {
        [activityIndicatorView stopAnimating];
    }else{
        [activityIndicatorView startAnimating];
    }
    isProgressShow = !isProgressShow;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen]applicationFrame]];
    self.view = contentView;
//    [self.view addSubview:contentView];
    contentView.backgroundColor = [UIColor blackColor];
   
    
    activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
    [activityIndicatorView setCenter:contentView.center];
    [contentView addSubview:activityIndicatorView];
    activityIndicatorView.hidesWhenstopped = YES; //停止后隐藏

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button setFrame:CGRectMake(100, 100, 100, 30)];
    [button setBackgroundColor:[UIColor redColor]];
    [button setTitle:@"start/stop" forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonClicked) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:button];
    
    isProgressShow = NO;

    [contentView release];
    [activityIndicatorView release];
}
posted @ 2012-08-24 13:59  小、  阅读(420)  评论(0编辑  收藏  举报