首页 > 代码库 > UIActivityIndicatorView 的使用

UIActivityIndicatorView 的使用

//
//  UIActivityIndicator.m
//  ToolBar
//
//  Created by lanouhn on 15/1/3.
//  Copyright (c) 2015 niutiantian. All rights reserved.
//

#import "UIActivityIndicator.h"

@interface UIActivityIndicator ()
{
    UIActivityIndicatorView *activityView;
}
@end

@implementation UIActivityIndicator

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    UIActivityIndicatorView: 风火轮视图,作用是提醒用户正在加载数据
    
        //风火轮的样式
//    UIActivityIndicatorViewStyleWhiteLarge大型白色指示器
//    UIActivityIndicatorViewStyleWhite标准尺寸白色只指示器
//    UIActivityIndicatorViewStyleGray灰色指示器,用于白色背景

    activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    activityView.frame = CGRectMake(0, 0, 40, 40);
    activityView.center = self.view.center;
        //设置颜色
    activityView.color = [UIColor redColor];
    
        //指示器停止后自动隐藏
    activityView.hidesWhenStopped = YES;
    
    [self.view addSubview:activityView];
    [activityView release];
    
    UIButton *starButton = [UIButton buttonWithType:UIButtonTypeSystem];
    starButton.frame = CGRectMake(100, 100, 40, 40);
    [starButton setTitle:@"开始" forState:UIControlStateNormal];
    
    [starButton addTarget:self action:@selector(starAnimation) forControlEvents:UIControlEventTouchUpInside];
    
    
    [self.view addSubview:starButton];
    
    UIButton *stopButton = [UIButton buttonWithType:UIButtonTypeSystem];    stopButton.frame = CGRectMake(100, 160, 40, 40);    [stopButton setTitle:@"停止" forState:UIControlStateNormal];    [stopButton addTarget:self action:@selector(stopAnimation) forControlEvents:UIControlEventTouchUpInside];    [self.view addSubview:stopButton];    }- (void)starAnimation{    [activityView startAnimating];//开启动画}- (void)stopAnimation{    [activityView stopAnimating];//关闭动画}@end

 

UIActivityIndicatorView 的使用