iOS UIActivityIndicatorView的简单使用

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor grayColor];
    
    UIActivityIndicatorView *activityView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    activityView.frame=CGRectMake(60, 130, 200, 200);//其大小不变
//    activityView.center=CGPointMake(160, 230);
    [activityView startAnimating];
    
    [self.window addSubview:activityView];
    [activityView release];
    
    [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateInfo:) userInfo:activityView repeats:NO];
    //设置通知栏的ActivityIndicator
     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
    
    [self.window makeKeyAndVisible];
    return YES;
}

-(void)updateInfo:(NSTimer *)timer
{
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
    //获取
    UIActivityIndicatorView *activityView=[timer userInfo];
    //停止
    [activityView stopAnimating];
    //从父视图移除
//    [activityView removeFromSuperview];
    
}

你可能感兴趣的:(iOS UIActivityIndicatorView的简单使用)