// // customToastVew.m // Private-X // // Created by xd h on 2024/7/18. // #import "customToastVew.h" @interface customToastVew () @property(nonatomic,copy)NSString*curText; @property(nonatomic,strong)UILabel*textlabel; @end @implementation customToastVew static customToastVew * _instance; + (customToastVew*)makeText:(NSString*)text { [customToastVew shardInstance].curText = text; return [customToastVew shardInstance]; } + (instancetype)shardInstance { static dispatch_once_t customToastVewOnceToken; dispatch_once(&customToastVewOnceToken, ^{ _instance = [[self alloc] init]; }); return _instance; } - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self drawAnyView]; } return self; } - (void)drawAnyView { CGFloat titleSize = 16.f; //UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, textSize.width + 20, textSize.height + 20)]; _textlabel = [[UILabel alloc] init]; _textlabel.backgroundColor = [UIColor clearColor]; _textlabel.textAlignment = NSTextAlignmentCenter; _textlabel.textColor = [UIColor whiteColor]; _textlabel.font = [UIFont systemFontOfSize:titleSize]; _textlabel.numberOfLines = 0; self.backgroundColor = [UIColor hwColor:@"#000000" alpha:0.8]; self.layer.cornerRadius = 8; self.layer.masksToBounds = YES; [self addSubview:_textlabel]; } - (void)show { CGFloat titleSize = 16.f; CGSize textSize = [_curText boundingRectWithSize:CGSizeMake([UIScreen mainScreen].bounds.size.width * 0.75, 100) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:titleSize], NSForegroundColorAttributeName:[UIColor whiteColor]} context:nil].size; _textlabel.frame = CGRectMake(10, 10, textSize.width + 20, textSize.height + 20); _textlabel.text = _curText; self.frame = CGRectMake((SCREEN_W - (textSize.width + 40))/2, (SCREEN_H - (textSize.height + 40))/2, textSize.width + 40, textSize.height + 40); [ksharedAppDelegate.window insertSubview:self atIndex:0]; //[ksharedAppDelegate.mainTabBar.view insertSubview:self atIndex:0]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self hideFun]; }); } -(void)hideFun { [self removeFromSuperview]; } @end