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.titleMargins = DLAVTextControlMarginsMake(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, 0, 0, 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];
}
}];