关于MBProgressHUD自定义帧动画

现在很多APP的HUD已经都是自定义动画了,MBProgressHUD没有开放的API可以让我们直接使用,需要到.m文件中去修改源码。

首先在.m文件中找到

- (void)updateIndicators

方法

if (mode == MBProgressHUDModeIndeterminate) {}

中自定义动画,然后上代码:

if (mode == MBProgressHUDModeIndeterminate) {
		if (!isActivityIndicator) {
			// Update to indeterminate indicator
			[indicator removeFromSuperview];
			self.indicator = MB_AUTORELEASE([[UIActivityIndicatorView alloc]
											 initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]);
            self.indicator = MB_AUTORELEASE([[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 70, 40)]);
            self.indicator.contentMode = UIViewContentModeScaleAspectFit;
//			[(UIActivityIndicatorView *)indicator startAnimating];
			[self addSubview:indicator];
            
            for (int i=0; i<24; i++) {
                [_loadingArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"loading_%d",i + 1]]];
            }
            
            
            //设置动画数组
            [(UIImageView *)self.indicator setAnimationImages:_loadingArray];
            //设置动画播放次数
            [(UIImageView *)self.indicator setAnimationRepeatCount:MAXFLOAT];
            //设置动画播放时间
            [(UIImageView *)self.indicator setAnimationDuration:1.5];
            //开始动画
            [(UIImageView *)self.indicator startAnimating];
		}
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 50000
        if ([indicator isKindOfClass:[UIActivityIndicatorView class]]) {
            [(UIActivityIndicatorView *)indicator setColor:self.activityIndicatorColor];
        }
		
#endif
	}

感兴趣的朋友可以尝试一下



你可能感兴趣的:(iOS)