// // PopWaitAlert.m // PopupViewWrapper // // Created by Rui Zhang on 3/20/23. // Copyright © 2023 yangyi. All rights reserved. // #import "PopWaitAlert.h" #import "RAUtils.h" @interface PopWaitAlert () @property (nonatomic , copy) void (^completion)(void); //+ (instancetype)sharedInstance; //(void (^ __nullable)(void)) completion; @end @implementation PopWaitAlert //+ (instancetype)sharedInstance { // // static PopWaitAlert *singleton = nil; // static dispatch_once_t onceToken; // dispatch_once(&onceToken, ^{ // // singleton = [[PopWaitAlert alloc] init]; //// [[NSNotificationCenter defaultCenter] addObserver:singleton selector:@selector(handleLogin:) name:User_LoginOK_Notification object:nil]; // // // //// self addObserver:self forKeyPath:self.scan_cart options:<#(NSKeyValueObservingOptions)#> context:<#(nullable void *)#> // }); // return singleton; //} + (instancetype)Show:(NSString*) title message:(NSString*) message completion:(void (^ __nullable)(void))completion { if(title==nil) title=@""; if(message==nil) message=@""; PopWaitAlert *pa =[[PopWaitAlert alloc] init:completion]; // [pa setCompletion:completion]; [pa setCenter : [RAUtils keyWindow].center ]; [pa setTitle:title]; [pa setMessage:message]; RAPopviewContainer *wrapper = [[RAPopviewContainer alloc] initWithView:pa]; wrapper.modalView=true; wrapper.bgColor = [UIColor colorWithWhite:0 alpha:0.2]; [wrapper show:[RAUtils keyWindow]]; return pa; } -(void)updateframe { int h = 0; h=_labelTitle.frame.size.height+10+_labelMessage.frame.size.height+10+20; CGRect newframe = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width,h); self.frame = newframe; } -(void)setMessage:(NSString*)messageText { _labelMessage.text = messageText; _labelMessage.frame = CGRectMake(16, 45, self.frame.size.width-32, 40); [_labelMessage sizeToFit]; [self updateframe]; } -(void)setTitle:(NSString*)titleText { _labelTitle.text = titleText; _labelTitle.frame = CGRectMake(30, 10, self.frame.size.width-60, 40); [_labelTitle sizeToFit]; [self updateframe]; } - (void)hide { // [UIView animateWithDuration:0.25 animations:^{ // CGRect frame = self.frame; // frame.origin.y = self.superview.frame.size.height; // self.frame = frame; // } completion:^(BOOL finished) { [super hide]; if(self.completion) self.completion(); // }]; } - (instancetype)init:(void (^ __nullable)(void))completion { self.completion=completion; return [self init]; } - (instancetype)init { return [self initWithFrame:CGRectMake(0, 0, 270, 180)]; } - (instancetype)initWithFrame:(CGRect)frame { if (self = [super initWithFrame:frame]) { self.backgroundColor=[UIColor whiteColor]; self.layer.cornerRadius = 15.0f; self.layer.masksToBounds = YES; self.layer.borderColor=[UIColor darkGrayColor].CGColor; self.layer.borderWidth=0.2; self.layer.shadowRadius = self.layer.cornerRadius + 5; self.layer.shadowOpacity = 0.1f; self.layer.shadowOffset = CGSizeMake(0 - (self.layer.cornerRadius+5)/2, 0 - (self.layer.cornerRadius+5)/2); self.layer.shadowColor = [UIColor blackColor].CGColor; self.layer.shadowPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds cornerRadius:self.layer.cornerRadius].CGPath; // UILabel *clabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, frame.size.width-20, 100)]; // clabel.textAlignment = NSTextAlignmentCenter; // clabel.text = @"Title Title Title Title"; // clabel.font=[UIFont boldSystemFontOfSize:17.0f]; // [clabel setLineBreakMode:NSLineBreakByWordWrapping]; // // [clabel setNumberOfLines:2]; // // [clabel sizeToFit]; // _labelTitle = [[UILabel alloc] initWithFrame:CGRectMake(30, 10, frame.size.width-60, 40)]; _labelTitle.textAlignment = NSTextAlignmentCenter; _labelTitle.text = @"Please Wait..."; _labelTitle.font=[UIFont boldSystemFontOfSize:20.0f]; [_labelTitle setLineBreakMode:NSLineBreakByWordWrapping]; [_labelTitle setNumberOfLines:1]; [_labelTitle sizeToFit]; [self addSubview:_labelTitle]; _labelTitle.translatesAutoresizingMaskIntoConstraints = NO; NSLayoutConstraint *T_hl = [NSLayoutConstraint constraintWithItem:_labelTitle attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeading multiplier:1 constant:30]; NSLayoutConstraint *T_ht = [NSLayoutConstraint constraintWithItem:_labelTitle attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTrailing multiplier:1 constant:-30]; NSLayoutConstraint *T_vt = [NSLayoutConstraint constraintWithItem:_labelTitle attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1 constant:10]; // NSLayoutConstraint *width = [NSLayoutConstraint constraintWithItem:hud // attribute:NSLayoutAttributeWidth // relatedBy:NSLayoutRelationEqual // toItem:nil // attribute:NSLayoutAttributeNotAnAttribute // multiplier:0 // constant:HUDSIZE]; // NSLayoutConstraint *height = [NSLayoutConstraint constraintWithItem:hud // attribute:NSLayoutAttributeHeight // relatedBy:NSLayoutRelationEqual // toItem:nil // attribute:NSLayoutAttributeNotAnAttribute // multiplier:0 // constant:HUDSIZE]; [self addConstraints:@[T_hl,T_ht,T_vt]]; // CGSize maxSizeTitle =[labelTitle sizeThatFits:labelTitle.frame.size]; _labelMessage = [[UILabel alloc] initWithFrame:CGRectMake(16, 45, frame.size.width-32, 40)]; _labelMessage.textAlignment = NSTextAlignmentCenter; _labelMessage.text = @"Message"; _labelMessage.font=[UIFont systemFontOfSize:16.0f]; [_labelMessage setLineBreakMode:NSLineBreakByWordWrapping]; [_labelMessage setNumberOfLines:1]; [_labelMessage sizeToFit]; [self addSubview:_labelMessage]; _labelMessage.translatesAutoresizingMaskIntoConstraints = NO; NSLayoutConstraint *M_hl = [NSLayoutConstraint constraintWithItem:_labelMessage attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeading multiplier:1 constant:16]; NSLayoutConstraint *M_ht = [NSLayoutConstraint constraintWithItem:_labelMessage attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTrailing multiplier:1 constant:-16]; NSLayoutConstraint *M_vt = [NSLayoutConstraint constraintWithItem:_labelMessage attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:_labelTitle attribute:NSLayoutAttributeBottom multiplier:1 constant:10]; [self addConstraints:@[M_hl,M_ht,M_vt]]; // labelTitle.text = @"Title Title Title Title Title Title Title"; // [labelTitle sizeToFit]; [self updateframe]; // [self sizeToFit]; // self resize } return self; } /* // Only override drawRect: if you perform custom drawing. // An empty implementation adversely affects performance during animation. - (void)drawRect:(CGRect)rect { // Drawing code } */ @end