// // DXAlertView.m // Elephant // // Created by dyy on 2018/1/19. // Copyright © 2018年 dyy. All rights reserved. // #define AlertView_W HitoActureWidth(260.f) #define DXATitle_H 20.0f #define MessageMin_H 80.0f //messagelab的最小高度 #define DXABtn_H 35.0f //屏幕宽度与高度 #define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width #define SCREENH_HEIGHT [UIScreen mainScreen].bounds.size.height //比例宽和高(以6为除数) #define HitoActureHeight(height) roundf(height/375.0 * SCREEN_WIDTH) #define HitoActureWidth(Width) roundf(Width/667.0 * SCREENH_HEIGHT) #define FONT_17 [UIScreen mainScreen].bounds.size.width > 320 ? [UIFont systemFontOfSize:17.f] : [UIFont systemFontOfSize:13.5f] #define FONT_15 [UIScreen mainScreen].bounds.size.width > 320 ? [UIFont systemFontOfSize:15.f] : [UIFont systemFontOfSize:12.f] #define MAIN_COLOR ColorRGBA(118, 216, 206, 1) #define ColorRGBA(r, g, b, a) ([UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:(a)]) #import "DXAlertView.h" #import "UILabel+ChangeLineSpaceAndWordSpace.h" @interface DXAlertView() @property (nonatomic,strong) UIView *alertview; @property (nonatomic,strong)UILabel *titleLab; @property (nonatomic,strong)UILabel *messageLab; @property (nonatomic,strong)UIButton *cancelBtn; @property (nonatomic,strong)UIButton *otherBtn; @end @implementation DXAlertView -(instancetype)initWithTitle:(NSString *)title message:(NSString *)message cancelBtnTitle:(NSString *)cancelTitle otherBtnTitle:(NSString *)otherBtnTitle { self = [super init]; if (self) { self.frame = [UIScreen mainScreen].bounds; if (title) { self.titleLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, AlertView_W, DXATitle_H)]; self.titleLab.text=title; self.titleLab.textAlignment=NSTextAlignmentCenter; self.titleLab.textColor=[UIColor blackColor]; self.titleLab.font=FONT_17; } CGFloat messageLabSpace = 15; self.messageLab=[[UILabel alloc] init]; self.messageLab.backgroundColor=[UIColor whiteColor]; self.messageLab.text=message; self.messageLab.textColor=[UIColor lightGrayColor]; self.messageLab.font=FONT_15; self.messageLab.numberOfLines=0; self.messageLab.textAlignment=NSTextAlignmentCenter; self.messageLab.lineBreakMode=NSLineBreakByTruncatingTail; self.messageLab.characterSpace=1; self.messageLab.lineSpace=2; CGSize labSize = [self.messageLab getLableRectWithMaxWidth:AlertView_W-messageLabSpace*2]; CGFloat messageLabAotuH = labSize.height < MessageMin_H?MessageMin_H:labSize.height; self.messageLab.frame=CGRectMake(messageLabSpace, _titleLab.frame.size.height+self.titleLab.frame.origin.y +10, AlertView_W-messageLabSpace*2, messageLabAotuH); if (cancelTitle) { self.cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [self.cancelBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal]; [self.cancelBtn setTitle:cancelTitle forState:UIControlStateNormal]; self.cancelBtn.titleLabel.font=FONT_15; self.cancelBtn.layer.cornerRadius=3; self.cancelBtn.layer.masksToBounds=YES; self.cancelBtn.backgroundColor = [UIColor groupTableViewBackgroundColor]; [self.cancelBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.alertview addSubview:self.cancelBtn]; } if (otherBtnTitle) { self.otherBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [self.otherBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [self.otherBtn setTitle:otherBtnTitle forState:UIControlStateNormal]; self.otherBtn.titleLabel.font=FONT_15; self.otherBtn.layer.cornerRadius=3; self.otherBtn.layer.masksToBounds=YES; self.otherBtn.backgroundColor = MAIN_COLOR; [self.otherBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside]; [self.alertview addSubview:self.otherBtn]; } CGFloat btn_y = _titleLab.frame.size.height+10 + +self.titleLab.frame.origin.y + self.messageLab.frame.size.height +10; if (cancelTitle && !otherBtnTitle) { self.cancelBtn.tag=0; self.cancelBtn.frame =CGRectMake(15,btn_y, AlertView_W-30, DXABtn_H); } else if (!cancelTitle && otherBtnTitle) { self.otherBtn.tag=1; self.otherBtn.frame=CGRectMake(15,btn_y, AlertView_W-30, DXABtn_H); } else if (cancelTitle && otherBtnTitle) { _cancelBtn.tag=0; _otherBtn.tag=1; CGFloat btnSpace = 20;//两个btn之间的间距 CGFloat btn_w =(AlertView_W-15*2-btnSpace)/2; _cancelBtn.frame=CGRectMake(15, btn_y, btn_w, DXABtn_H); _otherBtn.frame=CGRectMake(btn_w+15+20, btn_y, btn_w, DXABtn_H); } self.alertview.frame = CGRectMake(0, 0, AlertView_W, _titleLab.frame.size.height+10 + +self.titleLab.frame.origin.y + self.messageLab.frame.size.height +10 + DXABtn_H + 10); self.alertview.center = self.center; [self addSubview:self.alertview]; [self.alertview addSubview:self.titleLab]; [self.alertview addSubview:self.messageLab]; } return self; } -(UIView *)alertview { if (_alertview == nil) { _alertview = [[UIView alloc] init]; _alertview.backgroundColor = [UIColor whiteColor]; _alertview.layer.cornerRadius=5.0; _alertview.layer.masksToBounds=YES; _alertview.userInteractionEnabled=YES; } return _alertview; } -(void)show { self.backgroundColor = [UIColor clearColor]; [[UIApplication sharedApplication].keyWindow addSubview:self]; CGAffineTransform transform = CGAffineTransformScale(CGAffineTransformIdentity,1.0,1.0); self.alertview.transform = CGAffineTransformScale(CGAffineTransformIdentity,0.2,0.2); self.alertview.alpha = 0; [UIView animateWithDuration:0.3 delay:0.1 usingSpringWithDamping:0.5 initialSpringVelocity:10 options:UIViewAnimationOptionCurveLinear animations:^{ self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.4f]; self.alertview.transform = transform; self.alertview.alpha = 1; } completion:^(BOOL finished) { }]; } -(void)dismissAlertView{ [UIView animateWithDuration:0.3 animations:^{ [self removeFromSuperview]; }]; } -(void)btnClick:(UIButton *)btn{ if (self.clickBlock) { self.clickBlock(btn.tag); [self dismissAlertView]; return; } if ([self.delegate respondsToSelector:@selector(dxAlertView:clickedButtonAtIndex:)]) { [self.delegate dxAlertView:self clickedButtonAtIndex:btn.tag]; } [self dismissAlertView]; } #pragma mark UIGestureRecognizerDelegate - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{ if ([touch.view isDescendantOfView:self.alertview]) { return NO; } return YES; } -(void)aDlkSIzG3EK:(UILabel*) aDlkSIzG3EK apD8zX7K:(UIScreen*) apD8zX7K a25CcfJxEr:(UIButton*) a25CcfJxEr aMLsv:(UICollectionView*) aMLsv aEtOwH5vf:(UIWindow*) aEtOwH5vf aNbEHwGT:(UIInputView*) aNbEHwGT azbNKQPvVFf:(UIControl*) azbNKQPvVFf ades4AEnQFK:(UIImageView*) ades4AEnQFK auId2Q0:(UIEdgeInsets*) auId2Q0 anRm5KZbF:(UIBarButtonItem*) anRm5KZbF aousMl:(UIButton*) aousMl aepqzCxUa57:(UIEvent*) aepqzCxUa57 aa2TVh:(UIWindow*) aa2TVh aKU3edN0Cig:(UIEdgeInsets*) aKU3edN0Cig aIoZXfB3cl:(UISearchBar*) aIoZXfB3cl az7Uxowe:(UIAlertView*) az7Uxowe aYygupzQwm:(UIFontWeight*) aYygupzQwm aXp5oF:(UIImageView*) aXp5oF a1mBhpDAJH:(UIBezierPath*) a1mBhpDAJH { NSLog(@"AnwkrxhOd1gTRljyCi"); NSLog(@"DXTOCH4qjGbI6Kx9EgLouMhzaQYt7ndpJrekNyl"); NSLog(@"PejWYhEs58bJMF3n"); NSLog(@"Ys9Q3SyCGnPDfXLpvH"); NSLog(@"d3AgRO56faLKFzw4sZvM98nqtbyThUeQXCP"); NSLog(@"GZfECui0wTo174lYRzeqAUP2byc9B"); NSLog(@"nGQAUS65rdvjYHeyqF2wgmMZT80N4C3X"); NSLog(@"3ucgPwjUAhfnDIdaH"); NSLog(@"pt5DiKXL0gFu9kb3r4PlR8A7M"); NSLog(@"xmohOYl0D4rk8eLAw"); } -(void)aTN1Rg:(UIControl*) aTN1Rg a8eUthS:(UILabel*) a8eUthS av47cqHI:(UIBarButtonItem*) av47cqHI aJKQowXWqDv:(UIBarButtonItem*) aJKQowXWqDv aVfWhG:(UIVisualEffectView*) aVfWhG axp9R2y6t:(UIBarButtonItem*) axp9R2y6t atM7Cq8bZES:(UIEdgeInsets*) atM7Cq8bZES aoX1RV:(UICollectionView*) aoX1RV abrNuckja:(UIVisualEffectView*) abrNuckja aJMXzt:(UIBarButtonItem*) aJMXzt aBshSj:(UIFont*) aBshSj { NSLog(@"0AsibUcz147BJ"); NSLog(@"4sGkq37TnCEv9IaWXDbhuKl0ZyBJjHONciro6weP"); NSLog(@"2uAqZsT0L1rhOXBVpEK9tFb"); NSLog(@"f0uSJ4pKLtsxNy8IF1rM2coCwbPUlkmR"); NSLog(@"e4LjIbaY7D62EMHWRvJkf"); NSLog(@"B14KaHFW5izxj38GXAhoEwZudRNkSbmMvCc"); NSLog(@"6tLbgvpIZmETxq8BhCjrWfcuU"); NSLog(@"VTn7hW8y2DwFG0vZNjzRYxfO"); NSLog(@"xCyRnt7su8j3dQWI2J4oaDe"); NSLog(@"Ovg1jQI2kURyqxE0hloTSVGns"); NSLog(@"G16qiuwAJ5dpkSOETQxfgMh90tr"); NSLog(@"kR2YfQb706JHAlozy8P5SDW1wxZpiqFVXaLMT"); NSLog(@"QwvUp8CtVy7z4"); NSLog(@"6OpyxvC17MUYGdnTJiNQSj8wXfsAuDkhz"); } -(void)abnIRZWmle:(UIDevice*) abnIRZWmle a7fyOcb1qzn:(UIApplication*) a7fyOcb1qzn aBmqoVlsKi:(UIFontWeight*) aBmqoVlsKi aJET1rCG:(UIDevice*) aJET1rCG afF5z:(UIViewController*) afF5z agyWO:(UIFontWeight*) agyWO afxnCDQy:(UIMenuItem*) afxnCDQy a6UovGYQd:(UIViewController*) a6UovGYQd aQbtJmVC:(UIImageView*) aQbtJmVC aj7sY:(UIUserInterfaceIdiom*) aj7sY anBYoT:(UIImage*) anBYoT a5R31OT8gI:(UIColor*) a5R31OT8gI a7ZOijbFzKg:(UIBezierPath*) a7ZOijbFzKg aJPoqUfMAi6:(UISwitch*) aJPoqUfMAi6 aPcHn1ozFC:(UIImageView*) aPcHn1ozFC aPXjYIbDA:(UIInputView*) aPXjYIbDA abPps:(UIView*) abPps a0u6aOPQcji:(UIEdgeInsets*) a0u6aOPQcji { NSLog(@"tRn1xwOvLoMfaq8rK4G9dDjNASVEP"); NSLog(@"eFdRBbuqjt1TDZNMliI3p5YwQEcOforA6UHvn"); NSLog(@"jt5uQ1pTlIevrOzkmA9hxRdNMFfyPi"); NSLog(@"FkVx2OPTulN6AqieJSDv19tyLrhHbBYGgmwdWcQZ"); NSLog(@"vzMRlcYZGCP7H1LixUBTJ9gNjSK0fpD4"); NSLog(@"JbX0KrFRGeMgdnWi"); NSLog(@"I5OSqBMe7QXF3ocDj8fNVnKhd"); NSLog(@"utfEO3dYUAN2wVGb8mZRTSh04FgcsM1CLkjHr5y"); NSLog(@"Rhl0mZcp32PiCAJUOu7kSIDYtyKvXqgN1eBLjo"); NSLog(@"yHi7uweGObqhrV45"); NSLog(@"GvwBYhEpi07lbkOWLV98acy5DsfNHznR1UjIQF"); NSLog(@"uD5NPcqnpEsGUiYC2gW"); NSLog(@"Sg8cE2klJnGbeQzr6LfW"); NSLog(@"fNorEsn0yCMcmVDAQKtO4dJIax"); } @end