iOS学习 DLAVAlertView的使用

                DLAVAlertView *alertView = [[DLAVAlertView alloc] initWithTitle:@"选择模式" message:nil delegate:self cancelButtonTitle:@"企业模式" otherButtonTitles:@"个人模式", nil];

                alertView.maxContentWidth = CGRectGetWidth([UIScreen mainScreen].bounds)-50;

                alertView.alertViewStyle = DLAVAlertViewStyleDefault;

                alertView.dismissesOnBackdropTap = YES;

                DLAVAlertViewTheme *theme = [DLAVAlertViewTheme defaultTheme];  //主题样式设置  选择模式

                theme.titleFont = [UIFont systemFontOfSize:16];

                theme.backgroundColor = [UIColor whiteColor];  //提示框背景颜色

                theme.titleMarginsDLAVTextControlMarginsMake(8.0, 8.0, 12.0, 12.0);

                theme.titleColor = [UIColor grayColor];     //主题字颜色

                theme.titleBackgroundColor = [UIColor colorWithRed:0.95f green:0.95f blue:0.96f alpha:1.00f]; //主题字背景颜色

                theme.lineWidth = 0.0;

                theme.lineColor = [UIColor clearColor];

                DLAVAlertViewButtonTheme *leftButtonTheme = [DLAVAlertViewButtonTheme theme]; //左按钮

                leftButtonTheme.height = 35.0;

                leftButtonTheme.margins = DLAVTextControlMarginsMake(0.0, 0, 0, 0);

                leftButtonTheme.backgroundColor = [UIColor colorWithRed:0.35f green:0.71f blue:0.99f alpha:1.00f];

                leftButtonTheme.highlightBackgroundColor = [UIColor colorWithRed:0.35f green:0.71f blue:0.99f alpha:0.50f];

                leftButtonTheme.textColor = [UIColor whiteColor];

                [alertView setCustomButtonTheme:leftButtonTheme forButtonAtIndex:0];

                DLAVAlertViewButtonTheme *rightButtonTheme = [DLAVAlertViewButtonTheme theme];//右按钮

                rightButtonTheme.height = 35.0;

                rightButtonTheme.margins = DLAVTextControlMarginsMake(0.0, 00, 0);

                rightButtonTheme.backgroundColor = [UIColor colorWithRed:0.49f green:0.79f blue:0.99f alpha:1.00f];

                rightButtonTheme.highlightBackgroundColor = [UIColor colorWithRed:0.49f green:0.79f blue:0.99f alpha:0.50f];

                rightButtonTheme.textColor = [UIColor whiteColor];

                [alertView setCustomButtonTheme:rightButtonTheme forButtonAtIndex:1];

                [alertView applyTheme:theme];

                UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];  //关闭对话框按钮

                [closeBtn setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];

                [alertView addSubview:closeBtn];

                [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {

                    make.top.equalTo(@(2));

                    make.right.equalTo(@(-2));

                    make.width.equalTo(@(30));

                    make.height.equalTo(@(30));

                }];

                [closeBtn addTarget:self action:@selector(closeButtonClicked:) forControlEvents:UIControlEventTouchUpInside];

                

                UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, alertView.maxContentWidth, 70.0)];

                contentView.backgroundColor = [UIColor whiteColor];  //对话框中间内容视图

                

                __block UITextField *textField = [[UITextField alloc] init];

                textField.font = [UIFont systemFontOfSize:15];

                textField.borderStyle = UITextBorderStyleRoundedRect;

                textField.backgroundColor = [UIColor colorWithWhite:0.96 alpha:0.6];

                textField.placeholder = @"请输入企业码";

                textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;

                [contentView addSubview:textField];

                [textField mas_makeConstraints:^(MASConstraintMaker *make) {

                    make.top.equalTo(@(15));

                    make.left.equalTo(@(10));

                    make.right.equalTo(@(-10));

                }];

                UILabel *label = [[UILabel alloc] init];

                label.font = [UIFont systemFontOfSize:12];

                label.textColor = [UIColor grayColor];

                label.text = @"(个人模式可不填)";

                [contentView addSubview:label];

                [label mas_makeConstraints:^(MASConstraintMaker *make) {

                    make.top.equalTo(textField.mas_bottom).offset(2);

                    make.left.equalTo(@(6));

                    make.right.equalTo(@(-6));

                    make.height.equalTo(@(22));

                }];

                alertView.contentView = contentView;

                self.alertView = alertView;

                [alertView showWithCompletion:^(DLAVAlertView *alertView, NSInteger buttonIndex) {

                    NSLog(@"Tapped button '%@' at index: %ld", [alertView buttonTitleAtIndex:buttonIndex], (long)buttonIndex);

                    if (buttonIndex == 0) {//点击左按钮,响应方法

                        UITextField *tf=textField;

                        if (![CUtil IsEmpty:tf.text]) {

                            AccountEntity *user = [AppGlobalManager sharedAppGlobalManager].loginUser;

                            if (user && user.isLogin) {

                                NSMutableDictionary *dict=[NSMutableDictionary dictionary];

                                dict[@"userId"] = user.userId;

                                dict[@"companyCode"] = tf.text;

                                

                                [NetWorkTask getWithMethod:@"/album/help/saveNewCompany" forParamDic:dict succ:^(NSDictionary *successDict, id responseObject) {

                                    if ([successDict[@"resCode"] integerValue] == 0) {

                                        user.photoId = [NSString stringWithFormat:@"%@",successDict[@"resList"][@"photoId"]];

                                        user.photoStyle = successDict[@"resList"][@"style"];

                                        [user update];

                                        [AppGlobalManager sharedAppGlobalManager].loginUser = user;

                                        [self.tabBarController setSelectedIndex:indexPath.row+1];

                                    }else {

                                        UIAlertView *alert = [[UIAlertView alloc] initWithMessage:successDict[@"resMessage"] cancelButtonTitle:@"确定"];

                                        [alert show];

                                    }

                                } failure:^(NSDictionary *failDict, NSError *error) {

                                    UIAlertView *alert = [[UIAlertView alloc] initWithMessage:@"请输入正确的企业码" cancelButtonTitle:@"确定"];

                                    [alert show];

                                }];

                            }

                        } else {

                            UIAlertView *alert = [[UIAlertView alloc] initWithMessage:@"请输入正确的企业码" cancelButtonTitle:@"确定"];

                            [alert show];

                        }

                    } else if (buttonIndex == 1) {//点击右按钮,响应方法

                        [self.tabBarController setSelectedIndex:indexPath.row+1];

                    }

                }];



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值