iOS控件之UIActivityIndicatorView
UIActivityIndicatorView就是我们 常说的“风火轮”视图
作用:提示用户当前页面正在加载数据
常用属性和方法:
// 设置风格
@property(nonatomic) UIActivityIndicatorViewStyle activityIndicatorViewStyle;
// 停止时,隐藏视图,默认为YES
@property(nonatomic) BOOL hidesWhenStopped;
// 修改颜色,注意版本问题
@property (readwrite, nonatomic, retain) UIColor *color
// 开始动画
- (void)startAnimating;
// 停止动画
- (void)stopAnimating;
// 判断动画的状态(停止或开始)
- (BOOL)isAnimating;
project: ActivityViewDemo
打开 AppDelegate.m
在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions中的 [self.window makeKeyAndVisible]; 顶上加入
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activityView.center = CGPointMake(160, 200);
[activityView startAnimating];
// activityView.hidesWhenStopped = NO;
[self.window addSubview:activityView];
[NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(test:) userInfo:activityView repeats:NO];
//状态栏中的网络图标
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
加入方法
- (void)test:(NSTimer *)timer
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
UIActivityIndicatorView *activityView = [timer userInfo];
[activityView stopAnimating];
}
运行 风火轮 3秒钟都不转了