1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- //
- // KSProgressLoadingView.m
- // KulexiuSchoolStudent
- //
- // Created by 王智 on 2023/11/7.
- //
- #import "KSProgressLoadingView.h"
- @interface KSProgressLoadingView ()
- @property (weak, nonatomic) IBOutlet UIView *progressView;
- @property (weak, nonatomic) IBOutlet UIImageView *progressFillImage;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *imageWidth;
- @property (weak, nonatomic) IBOutlet UILabel *progressTipsLabel;
- @property (weak, nonatomic) IBOutlet NSLayoutConstraint *leadingSpace;
- @property (nonatomic, assign) NSInteger progress;
- @end
- @implementation KSProgressLoadingView
- + (instancetype)shareInstance {
- KSProgressLoadingView *view = [[[NSBundle mainBundle] loadNibNamed:@"KSProgressLoadingView" owner:nil options:nil] firstObject];
- return view;
- }
- - (void)configProgressWithText:(NSString *)tipsMessage progress:(NSInteger)progress {
- self.progressTipsLabel.text = tipsMessage;
- NSInteger space = progress * 1.0 / 100 * 280;
- self.progress = space;
- [UIView animateWithDuration:0.3f animations:^{
- self.leadingSpace.constant = space;
- }];
-
- }
- - (void)showLoadingView {
- UIWindow *windows = [NSObject getKeyWindow];
- [windows addSubview:self];
- [self mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.right.top.bottom.mas_equalTo(windows);
- }];
- }
- - (void)hideLoadingView {
- [self removeFromSuperview];
- }
- - (void)setProgress:(NSInteger)progress {
- _progress = progress;
- CGFloat width = progress;
- [self.progressFillImage setImage:[self createGradientImageWithColor:@[HexRGB(0x44F1D0),HexRGB(0x2DC7AA)] rect:CGRectMake(0, 0, width, 8) start:CGPointMake(0.41, 0) end:CGPointMake(0.41, 1)]];
- self.imageWidth.constant = width;
- }
- - (UIImage *)createGradientImageWithColor:(NSArray *)colors rect:(CGRect)rect start:(CGPoint)start end:(CGPoint)end {
- if (!colors.count || CGRectEqualToRect(rect, CGRectZero)) {
- return nil;
- }
- CAGradientLayer *gradientLayer = [CAGradientLayer layer];
-
- gradientLayer.frame = rect;
- gradientLayer.startPoint = start;
- gradientLayer.endPoint = end;
- NSMutableArray *mutColors = [NSMutableArray arrayWithCapacity:colors.count];
- for (UIColor *color in colors) {
- [mutColors addObject:(__bridge id)color.CGColor];
- }
- gradientLayer.colors = [NSArray arrayWithArray:mutColors];
-
- UIGraphicsBeginImageContextWithOptions(gradientLayer.frame.size, gradientLayer.opaque, 0);
- [gradientLayer renderInContext:UIGraphicsGetCurrentContext()];
- UIImage *outputImage = UIGraphicsGetImageFromCurrentImageContext();
- UIGraphicsEndImageContext();
- return outputImage;
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|