//
// activityViewController.m
// toolbar
//
// Created by Apple on 16/1/7.
// Copyright © 2016年 ShangYu. All rights reserved.
//
#import "activityViewController.h"
@interface activityViewController ()
@property (strong, nonatomic) UIActivityIndicatorView *activityIndicator ;
@property (nonatomic, strong) NSTimer *timer;//定时器 图片轮播
@end
@implementation activityViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor whiteColor];
// 使用方式就是
// UIActivityIndicatorView *testActivityIndicator = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
// testActivityIndicator.center = CGPointMake(100.0f, 100.0f);//只能设置中心,不能设置大小
// testActivityIndicator.frame= CGRectMake(100, 100, 100, 100);//不建议这样设置,因为UIActivityIndicatorView是不能改变大小只能改变位置,这样设置得到的结果是控件的中心在(100,100)上,而不是和其他控件的frame一样左上角在(100, 100)长为100,宽为100.
// [self.navigationController.navigationItem addSubview:testActivityIndicator];
// testActivityIndicator.color = [UIColor redColor]; // 改变圈圈的颜色为红色; iOS5引入
// [testActivityIndicator startAnimating]; // 开始旋转
// [testActivityIndicator stopAnimating]; // 结束旋转
// [testActivityIndicator setHidesWhenStopped:YES]; //当旋转结束时隐藏
[self avctiy];
}
-(void)avctiy{
self.activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(100, 100, 60, 60)];
[self.view addSubview:self.activityIndicator];
self.activityIndicator.backgroundColor=[UIColor redColor];
self.activityIndicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
[self.activityIndicator startAnimating];
[self addTimer];
//
// [NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(timerStop) userInfo:nil repeats:YES];
}
- (void)timerStop
{
[self.activityIndicator stopAnimating];
}
- (void)addTimer{
[self.activityIndicator startAnimating];
self.timer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(Timer) userInfo:nil repeats:YES];
}
/**
* 关闭定时器
*/
- (void)removeTimer
{
[self.timer invalidate];
}
-(void)Timer{
[self.activityIndicator stopAnimating];
}
@end