| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- //
- // MessageBox.m
- // PopupViewWrapper
- //
- // Created by Rui Zhang on 3/20/23.
- // Copyright © 2023 yangyi. All rights reserved.
- //
- #import "MessageBox.h"
- #import "RAUtils.h"
- @implementation MessageBox
- -(void)updateframe
- {
-
- int h = 0;
- h=self.labelTitle.frame.size.height+10+self.labelMessage.frame.size.height+10+_btnOK.frame.size.height+10+10;
-
- CGRect newframe = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width,h);
- self.frame = newframe;
-
- }
- //+ (instancetype)sharedInstance {
- //
- // static MessageBox *singleton = nil;
- // static dispatch_once_t onceToken;
- // dispatch_once(&onceToken, ^{
- //
- // singleton = [[MessageBox 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
- {
-
- MessageBox *mb =[[MessageBox alloc] init:completion];
-
- // [mb setCompletion:completion];
- [mb setCenter : [RAUtils keyWindow].center ];
- [mb setTitle:title];
- [mb setMessage:message];
- RAPopviewContainer *wrapper = [[RAPopviewContainer alloc] initWithView:mb];
- wrapper.modalView=true;
- wrapper.bgColor = [UIColor colorWithWhite:0 alpha:0.2];
- [wrapper show:[RAUtils keyWindow]];
- return mb;
- }
- - (instancetype)initWithFrame:(CGRect)frame {
- if (self = [super initWithFrame:frame]) {
- [self.labelTitle setNumberOfLines:2];
-
- [self.labelTitle sizeToFit];
-
-
- [self.labelMessage setNumberOfLines:4];
-
-
- [self.labelMessage sizeToFit];
-
- // self.layer.cornerRadius = 5.0f;
- // self.layer.masksToBounds = YES;
- //
- //// 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 = @"Title Title Title Title";
- // _labelTitle.font=[UIFont boldSystemFontOfSize:20.0f];
- // [_labelTitle setLineBreakMode:NSLineBreakByWordWrapping];
- //
- //
- //
- // [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(30, 45, frame.size.width-60, 40)];
- // _labelMessage.textAlignment = NSTextAlignmentLeft;//NSTextAlignmentCenter;
- // _labelMessage.text = @"Message";
- // [_labelMessage setLineBreakMode:NSLineBreakByWordWrapping];
- //
- //
- // [self addSubview:_labelMessage];
- //
- //
- // _labelMessage.translatesAutoresizingMaskIntoConstraints = NO;
- //
- // NSLayoutConstraint *M_hl = [NSLayoutConstraint constraintWithItem:_labelMessage
- // attribute:NSLayoutAttributeLeading
- // relatedBy:NSLayoutRelationEqual
- // toItem:self
- // attribute:NSLayoutAttributeLeading
- // multiplier:1
- // constant:30];
- //
- //
- // NSLayoutConstraint *M_ht = [NSLayoutConstraint constraintWithItem:_labelMessage
- // attribute:NSLayoutAttributeTrailing
- // relatedBy:NSLayoutRelationEqual
- // toItem:self
- // attribute:NSLayoutAttributeTrailing
- // multiplier:1
- // constant:-30];
- //
- // 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]];
-
- _btnOK = [[UIButton alloc] initWithFrame:CGRectMake(30, 20, 80, 40)];
- [_btnOK setTitle:@"OK" forState:UIControlStateNormal];
- [_btnOK setTitleColor:[UIColor systemBlueColor] forState:UIControlStateNormal];
- [_btnOK addTarget:self action:@selector(onBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
- [_btnOK sizeToFit];
- [self addSubview:_btnOK];
-
-
-
- _btnOK.translatesAutoresizingMaskIntoConstraints = NO;
-
- NSLayoutConstraint *B_h = [NSLayoutConstraint constraintWithItem:_btnOK
- attribute:NSLayoutAttributeCenterX
- relatedBy:NSLayoutRelationEqual
- toItem:self
- attribute:NSLayoutAttributeCenterX
- multiplier:1
- constant:0];
-
- NSLayoutConstraint *B_w = [NSLayoutConstraint constraintWithItem:_btnOK
- attribute:NSLayoutAttributeWidth
- relatedBy:NSLayoutRelationEqual
- toItem:nil
- attribute:NSLayoutAttributeNotAnAttribute
- multiplier:0
- constant:60];
-
- NSLayoutConstraint *B_vt = [NSLayoutConstraint constraintWithItem:_btnOK
- attribute:NSLayoutAttributeTop
- relatedBy:NSLayoutRelationEqual
- toItem:self.labelMessage
- attribute:NSLayoutAttributeBottom
- multiplier:1
- constant:10];
- [self addConstraints:@[B_h,B_w,B_vt]];
-
-
- // labelTitle.text = @"Title Title Title Title Title Title Title";
- // [labelTitle sizeToFit];
-
-
- [self updateframe];
- // [self sizeToFit];
- // self resize
- // int a=0;
- }
- return self;
- }
- - (void)onBtnClicked:(id)sender {
- // 可以调用基类的hide方法
- [super hide];
- }
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- @end
|