iOS学习 DLAVAlertView的使用
来源:互联网 发布:少年包青天2知乎 编辑:程序博客网 时间:2024/05/20 02:57
DLAVAlertView *alertView = [[DLAVAlertViewalloc] initWithTitle:@"选择模式"message:nildelegate:selfcancelButtonTitle:@"企业模式"otherButtonTitles:@"个人模式",nil];
alertView.maxContentWidth =CGRectGetWidth([UIScreenmainScreen].bounds)-50;
alertView.alertViewStyle =DLAVAlertViewStyleDefault;
alertView.dismissesOnBackdropTap =YES;
DLAVAlertViewTheme *theme = [DLAVAlertViewThemedefaultTheme]; //主题样式设置 选择模式
theme.titleFont = [UIFontsystemFontOfSize:16];
theme.backgroundColor = [UIColorwhiteColor]; //提示框背景颜色
theme.titleMargins = DLAVTextControlMarginsMake(8.0,8.0, 12.0, 12.0);
theme.titleColor = [UIColorgrayColor]; //主题字颜色
theme.titleBackgroundColor = [UIColorcolorWithRed:0.95fgreen:0.95fblue:0.96falpha:1.00f];//主题字背景颜色
theme.lineWidth =0.0;
theme.lineColor = [UIColorclearColor];
DLAVAlertViewButtonTheme *leftButtonTheme = [DLAVAlertViewButtonThemetheme]; //左按钮
leftButtonTheme.height =35.0;
leftButtonTheme.margins =DLAVTextControlMarginsMake(0.0,0, 0,0);
leftButtonTheme.backgroundColor = [UIColorcolorWithRed:0.35fgreen:0.71fblue:0.99falpha:1.00f];
leftButtonTheme.highlightBackgroundColor = [UIColorcolorWithRed:0.35fgreen:0.71fblue:0.99falpha:0.50f];
leftButtonTheme.textColor = [UIColorwhiteColor];
[alertView setCustomButtonTheme:leftButtonThemeforButtonAtIndex:0];
DLAVAlertViewButtonTheme *rightButtonTheme = [DLAVAlertViewButtonThemetheme];//右按钮
rightButtonTheme.height =35.0;
rightButtonTheme.margins =DLAVTextControlMarginsMake(0.0,0, 0,0);
rightButtonTheme.backgroundColor = [UIColorcolorWithRed:0.49fgreen:0.79fblue:0.99falpha:1.00f];
rightButtonTheme.highlightBackgroundColor = [UIColorcolorWithRed:0.49fgreen:0.79fblue:0.99falpha:0.50f];
rightButtonTheme.textColor = [UIColorwhiteColor];
[alertView setCustomButtonTheme:rightButtonThemeforButtonAtIndex:1];
[alertView applyTheme:theme];
UIButton *closeBtn = [UIButtonbuttonWithType:UIButtonTypeCustom]; //关闭对话框按钮
[closeBtn setImage:[UIImageimageNamed:@"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:selfaction:@selector(closeButtonClicked:)forControlEvents:UIControlEventTouchUpInside];
UIView *contentView = [[UIViewalloc] initWithFrame:CGRectMake(0.0,0.0, alertView.maxContentWidth,70.0)];
contentView.backgroundColor = [UIColorwhiteColor]; //对话框中间内容视图
__blockUITextField *textField = [[UITextFieldalloc] init];
textField.font = [UIFontsystemFontOfSize:15];
textField.borderStyle =UITextBorderStyleRoundedRect;
textField.backgroundColor = [UIColorcolorWithWhite:0.96alpha: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 = [[UILabelalloc] init];
label.font = [UIFontsystemFontOfSize:12];
label.textColor = [UIColorgrayColor];
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", [alertViewbuttonTitleAtIndex:buttonIndex], (long)buttonIndex);
if (buttonIndex ==0) {//点击左按钮,响应方法
UITextField *tf=textField;
if (![CUtilIsEmpty:tf.text]) {
AccountEntity *user = [AppGlobalManagersharedAppGlobalManager].loginUser;
if (user && user.isLogin) {
NSMutableDictionary *dict=[NSMutableDictionarydictionary];
dict[@"userId"] = user.userId;
dict[@"companyCode"] = tf.text;
[NetWorkTaskgetWithMethod:@"/album/help/saveNewCompany"forParamDic:dict succ:^(NSDictionary *successDict,id responseObject) {
if ([successDict[@"resCode"]integerValue] == 0) {
user.photoId = [NSStringstringWithFormat:@"%@",successDict[@"resList"][@"photoId"]];
user.photoStyle = successDict[@"resList"][@"style"];
[user update];
[AppGlobalManagersharedAppGlobalManager].loginUser = user;
[self.tabBarControllersetSelectedIndex:indexPath.row+1];
}else {
UIAlertView *alert = [[UIAlertViewalloc] initWithMessage:successDict[@"resMessage"]cancelButtonTitle:@"确定"];
[alert show];
}
} failure:^(NSDictionary *failDict,NSError *error) {
UIAlertView *alert = [[UIAlertViewalloc] initWithMessage:@"请输入正确的企业码"cancelButtonTitle:@"确定"];
[alert show];
}];
}
} else {
UIAlertView *alert = [[UIAlertViewalloc] initWithMessage:@"请输入正确的企业码"cancelButtonTitle:@"确定"];
[alert show];
}
} elseif (buttonIndex == 1) {//点击右按钮,响应方法
[self.tabBarControllersetSelectedIndex:indexPath.row+1];
}
}];
- iOS学习 DLAVAlertView的使用
- ios学习--SQLite3的使用
- IOS学习 CGAffineTransform的使用
- IOS 学习 PickView的使用
- iOS学习----NSNumber的使用
- ios学习--iOS下的Notification的使用
- ios学习--sqlite3数据库的使用
- iOS学习之UIActionSheet的使用
- iOS学习之WebView的使用
- iOS学习之WebView的使用
- iOS学习笔记6-delegate的使用
- IOS学习——UIActionSheet的使用
- iOS学习之UIActionSheet的使用
- iOS学习之UIActionSheet的使用
- ios学习笔记:UIAlertView的使用
- iOS学习之UIActionSheet的使用
- iOS学习之WebView的使用
- iOS学习之WebView的使用
- 表单按回车自动提交
- ASCII值的意义
- 大牛博客收藏
- c++ 继承(太详细了!!!)
- iOS代码调节音量、亮度不显示图标
- iOS学习 DLAVAlertView的使用
- Mybatis关联查询一对一和一对多的实现
- adb 命令模拟按键事件
- jQuery(function(){})与(function(){})(jQuery)的区别
- IDE--Netbeans to recognize shell script
- go结构体中String接口的实现为什么是结构体而不是指针
- 解决从系统相册取图片到系统剪切报错的问题
- Java annotation 自定义注释@interface的用法
- UIImageVIew的图片显示模式