3

我知道如何制作一个简单的方形背景的活动指示器,但根本没有填充,我不知道如何让“加载”一词显示为这样。

在此处输入图像描述

有谁知道这是如何实现的?我在网上查过,似乎找不到任何东西。谢谢你们!

4

3 回答 3

5

如果你想使用一些自定义组件,你可以使用MBProgressHUD。这是它的源代码

在此处输入图像描述

如果您想自己制作,您可以查看他们的源代码以了解他们是如何实现的,您可以对您的代码采用类似的方法。基本上,这将涉及在方法UIView中对活动指示器和标签进行子类化和绘制。drawRect

于 2012-12-21T07:54:36.030 回答
1

黑色背景是UIImageView. 所以在你想要显示这个的 viewController 中:

[self.view UIImageView]; //Set proper frame for the UIImageView so that it comes in the centre.

在该图像视图上,添加一个活动指示器和一个标有“正在加载”的标签。

我想这会给你你想要的。:)

于 2012-12-21T07:56:11.627 回答
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];

}

于 2012-12-21T07:56:54.383 回答