iOS开发-UIActivityIndicatorView简单使

2017-04-10  本文已影响40人  然亦伞

UIActivityIndicatorView提供轻型视图,会显示一个标准的旋转进度轮,只要添加到程序中,在合适的地方start和stop即可。start的时候可以吸附在当前视图中,stop的时候就会移除

简答的效果:

实现方式如下:

self.activityIndicatorView=[[UIActivityIndicatorView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];

self.activityIndicatorView.center=self.view.center;

[self.activityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleGray];

[self.activityIndicatorView setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];

[self.activityIndicatorView setBackgroundColor:[UIColor lightGrayColor]];

[self.view addSubview:self.activityIndicatorView];

[self.activityIndicatorView startAnimating];

代码很简单,设置frame这个不用讲,关于style的设置,有三种白色和灰色,这两种的尺寸都是20*20,白色大图是37*37:

typedef NS_ENUM(NSInteger, UIActivityIndicatorViewStyle) {

UIActivityIndicatorViewStyleWhiteLarge,

UIActivityIndicatorViewStyleWhite,

UIActivityIndicatorViewStyleGray,

};

关闭动画:

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5* NSEC_PER_SEC)), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{

[self.activityIndicatorView stopAnimating];

});

上一篇 下一篇

猜你喜欢

热点阅读