|
|
@@ -0,0 +1,203 @@
|
|
|
+//
|
|
|
+// YRAlertView.m
|
|
|
+// UU_Ent
|
|
|
+//
|
|
|
+// Created by liujl on 2019/5/7.
|
|
|
+// Copyright © 2019 UAS. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+#import "YRAlertView.h"
|
|
|
+
|
|
|
+static YRAlertView *alert = nil;
|
|
|
+
|
|
|
+@interface YRAlertView()
|
|
|
+
|
|
|
+@property(copy,nonatomic)void(^clicked)(NSInteger index);
|
|
|
+
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation YRAlertView
|
|
|
+
|
|
|
++(void)showWithTitle:(NSString *)title content:(NSString *)content sureTitle:(NSString *)sureTitle cancelTitle:(NSString *)cancelTitle click:(void(^)(NSInteger index))clicked{
|
|
|
+
|
|
|
+ if (!alert) {
|
|
|
+
|
|
|
+ alert = [[YRAlertView alloc]initWithFrame:[UIScreen mainScreen].bounds];
|
|
|
+
|
|
|
+ alert.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.2f];
|
|
|
+
|
|
|
+ [alert makeKeyAndVisible];
|
|
|
+
|
|
|
+ alert.clicked = clicked;
|
|
|
+
|
|
|
+ UIView *centView = [[UIView alloc]init];
|
|
|
+
|
|
|
+ centView.layer.cornerRadius = 8;
|
|
|
+ centView.layer.masksToBounds = YES;
|
|
|
+ centView.backgroundColor = [UIColor whiteColor];
|
|
|
+ [alert addSubview:centView];
|
|
|
+
|
|
|
+ [centView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+
|
|
|
+ make.center.equalTo(alert);
|
|
|
+ make.width.mas_equalTo(268);
|
|
|
+ make.height.mas_equalTo(150);
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ UILabel *titleL = [UILabel new];
|
|
|
+ titleL.font = FONT_SIZE(16);
|
|
|
+ titleL.textColor = HexColor(@"#333333");
|
|
|
+ titleL.textAlignment = NSTextAlignmentCenter;
|
|
|
+ [centView addSubview:titleL];
|
|
|
+ if (!title) {
|
|
|
+
|
|
|
+ title = @"UU互联";
|
|
|
+
|
|
|
+ }
|
|
|
+ titleL.text = title;
|
|
|
+ [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+
|
|
|
+ make.top.equalTo(centView).offset(11);
|
|
|
+ make.left.right.equalTo(centView);
|
|
|
+ make.height.mas_equalTo(21);
|
|
|
+
|
|
|
+ }];
|
|
|
+
|
|
|
+ UILabel *contentL = [UILabel new];
|
|
|
+ contentL.textAlignment = NSTextAlignmentLeft;
|
|
|
+ contentL.font = FONT_SIZE(15);
|
|
|
+ contentL.textColor = HexColor(@"#666666");
|
|
|
+ contentL.text = content;
|
|
|
+ contentL.numberOfLines = 0;
|
|
|
+ [centView addSubview:contentL];
|
|
|
+ contentL.lineBreakMode = NSLineBreakByCharWrapping;
|
|
|
+
|
|
|
+ CGSize contentSize = [content boundingRectWithSize:CGSizeMake(268 - 52, CGFLOAT_MAX) options:NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : FONT_SIZE(15)} context:NULL].size;;
|
|
|
+
|
|
|
+ [contentL mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.equalTo(centView).offset(51);
|
|
|
+ make.left.equalTo(centView).offset(26);
|
|
|
+ make.right.equalTo(centView).offset(-26);
|
|
|
+ if (contentSize.height > 40) {
|
|
|
+ make.height.mas_equalTo(contentSize.height);
|
|
|
+ }else{
|
|
|
+ make.height.mas_equalTo(40);
|
|
|
+ }
|
|
|
+ }];
|
|
|
+
|
|
|
+ if (contentSize.height > 40) {
|
|
|
+ [centView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.center.equalTo(alert);
|
|
|
+ make.width.mas_equalTo(268);
|
|
|
+ make.height.mas_equalTo(150+contentSize.height-40);
|
|
|
+ }];
|
|
|
+ }
|
|
|
+
|
|
|
+ UIButton *cancel = [UIButton new];
|
|
|
+ cancel.titleLabel.font = FONT_SIZE(15);
|
|
|
+ cancel.tag = 1;
|
|
|
+ cancel.layer.borderWidth = 1;
|
|
|
+ cancel.layer.borderColor = HexColor(@"33a2ee").CGColor;
|
|
|
+ [cancel setTitle:cancelTitle forState:UIControlStateNormal];
|
|
|
+ [cancel setTitle:cancelTitle forState:UIControlStateHighlighted];
|
|
|
+ [cancel setTitleColor:HexColor(@"#1084D1") forState:UIControlStateNormal];
|
|
|
+ [cancel setTitleColor:HexColor(@"#065C97") forState:UIControlStateHighlighted];
|
|
|
+ [cancel setBackgroundColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
|
+ [cancel setBackgroundColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
|
|
|
+ cancel.layer.cornerRadius = 5;
|
|
|
+ cancel.layer.masksToBounds = YES;
|
|
|
+ [cancel addTarget:alert action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+
|
|
|
+
|
|
|
+ UIButton *sure = [UIButton new];
|
|
|
+ sure.titleLabel.font = FONT_SIZE(15);
|
|
|
+ sure.tag = 2;
|
|
|
+ sure.layer.borderWidth = 1;
|
|
|
+ sure.layer.borderColor = HexColor(@"33A2EE").CGColor;
|
|
|
+ [sure setTitle:sureTitle forState:UIControlStateNormal];
|
|
|
+ [sure setTitle:sureTitle forState:UIControlStateHighlighted];
|
|
|
+ [sure setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
|
|
|
+ [sure setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
|
|
|
+ [sure setBackgroundColor:HexColor(@"33A2EE") forState:UIControlStateNormal];
|
|
|
+ [sure setBackgroundColor:HexColor(@"#2D84C0") forState:UIControlStateHighlighted];
|
|
|
+ sure.layer.cornerRadius = 5;
|
|
|
+ sure.layer.masksToBounds = YES;
|
|
|
+ [centView addSubview:sure];
|
|
|
+ [sure addTarget:alert action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+
|
|
|
+ if (cancelTitle) {
|
|
|
+ [centView addSubview:cancel];
|
|
|
+ [cancel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+
|
|
|
+ make.left.equalTo(centView).offset(26);
|
|
|
+ make.top.equalTo(contentL.mas_bottom).offset(10);
|
|
|
+ make.width.mas_equalTo(94);
|
|
|
+ make.height.mas_equalTo(35);
|
|
|
+
|
|
|
+ }];
|
|
|
+ [sure mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+
|
|
|
+ make.right.equalTo(centView).offset(-26);
|
|
|
+ make.top.equalTo(contentL.mas_bottom).offset(10);
|
|
|
+ make.width.mas_equalTo(94);
|
|
|
+ make.height.mas_equalTo(35);
|
|
|
+
|
|
|
+ }];
|
|
|
+ }else{
|
|
|
+
|
|
|
+
|
|
|
+ [sure mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+
|
|
|
+ make.centerX.equalTo(centView);
|
|
|
+ make.top.equalTo(contentL.mas_bottom).offset(10);
|
|
|
+ make.width.mas_equalTo(110);
|
|
|
+ make.height.mas_equalTo(35);
|
|
|
+
|
|
|
+ }];
|
|
|
+ }
|
|
|
+
|
|
|
+ CABasicAnimation *anima = [CABasicAnimation animationWithKeyPath:@"transform.scale"];
|
|
|
+ anima.fromValue = [NSNumber numberWithFloat:0.9f];
|
|
|
+ anima.toValue = [NSNumber numberWithFloat:1.0f];
|
|
|
+ anima.duration = 0.1f;
|
|
|
+ anima.repeatCount = 1;
|
|
|
+ [centView.layer addAnimation:anima forKey:@"scaleAnimation"];
|
|
|
+
|
|
|
+ }else{
|
|
|
+
|
|
|
+ [alert makeKeyAndVisible];
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
++(void)yyj_showWithTitle:(NSString *)title content:(NSString *)content sureTitle:(NSString *)sureTitle cancelTitle:(NSString *)cancelTitle click:(void(^)(NSInteger index))clicked{
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+-(void)buttonClicked:(UIButton *)btn{
|
|
|
+
|
|
|
+
|
|
|
+ if (self.clicked) {
|
|
|
+
|
|
|
+ self.clicked(btn.tag);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ [self resignKeyWindow];
|
|
|
+
|
|
|
+ alert = nil;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+-(void)dealloc{
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+@end
|