我知道如何使用简单的方形背景制作活动指示器,但根本没有填充,我不知道如何将“加载”这个词显示为这样。
有谁知道这是如何实现的?我看过网上似乎找不到任何东西。谢谢大家!
答案 0 :(得分:5)
如果您想使用某些自定义组件,可以使用MBProgressHUD。这是source code。
如果您想自己创建,可以查看他们的源代码以了解他们是如何实现这一点的,并且您可以按照类似的方法处理代码。基本上,这将涉及子类化UIView
并在drawRect
方法中绘制活动指示符和标签。
答案 1 :(得分:1)
黑色背景为UIImageView
。所以在你想要显示它的viewController中:
[self.view UIImageView]; //Set proper frame for the UIImageView so that it comes in the centre.
在该图片视图上,添加一个活动指示器和一个标有“正在加载”的标签。
我认为这会给你你想要的东西。 :)
答案 2 :(得分:1)
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
switch (self.maskType) {
case SVProgressHUDMaskTypeBlack: {
[[UIColor colorWithWhite:0 alpha:0.5] set];
CGContextFillRect(context, self.bounds);
break;
}
case SVProgressHUDMaskTypeGradient: {
size_t locationsCount = 2;
CGFloat locations[2] = {0.0f, 1.0f};
CGFloat colors[8] = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.75f};
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGGradientRef gradient = CGGradientCreateWithColorComponents(colorSpace, colors, locations, locationsCount);
CGColorSpaceRelease(colorSpace);
CGPoint center = CGPointMake(self.bounds.size.width / 2, self.bounds.size.height / 2);
float radius = MIN(self.bounds.size.width, self.bounds.size.height) ;
CGContextDrawRadialGradient(context, gradient, center, 0, center, radius, kCGGradientDrawsAfterEndLocation);
CGGradientRelease(gradient);
break;
}
}
}
+ (void)showWithStatus:(NSString *)status {
[SVProgressHUD showWithStatus:status networkIndicator:SVProgressHUDShowNetworkIndicator];
}
+ (void)showInView:(UIView *)view status:(NSString *)string {
[SVProgressHUD showWithStatus:string maskType:SVProgressHUDMaskTypeNone networkIndicator:SVProgressHUDShowNetworkIndicator];
}
- (void)showWithStatus:(NSString *)string maskType:(SVProgressHUDMaskType)hudMaskType networkIndicator:(BOOL)show {
self.fadeOutTimer = nil;
if (self.showNetworkIndicator)
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
self.showNetworkIndicator = show;
if (self.showNetworkIndicator)
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
self.imageView.hidden = YES;
self.maskType = hudMaskType;
[self setStatus:string];
[self.spinnerView startAnimating];
if (self.maskType != SVProgressHUDMaskTypeNone) {
self.overlayWindow.userInteractionEnabled = YES;
} else {
self.overlayWindow.userInteractionEnabled = NO;
}
[self.overlayWindow makeKeyAndVisible];
[self positionHUD:nil];
if (self.alpha != 1) {
[self registerNotifications];
self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 1.3, 1.3);
[UIView animateWithDuration:0.15
delay:0
options:UIViewAnimationOptionAllowUserInteraction | UIViewAnimationCurveEaseOut | UIViewAnimationOptionBeginFromCurrentState
animations:^{
self.hudView.transform = CGAffineTransformScale(self.hudView.transform, 1 / 1.3, 1 / 1.3);
self.alpha = 1;
}
completion:NULL];
}
[self setNeedsDisplay];
}