码迷,mamicode.com
首页 > 其他好文 > 详细

自定义alert弹框

时间:2017-10-20 20:06:45      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:round   present   nbsp   弹框   联系人   scale   tle   key   聊天   

 1 /**************** UIAlertControllerStyleAlert *************************/
 2 /*创建一个 可以自定义文字颜色和字体大小的IAlertView*/
 3 NSString *message = @"开通失败,请再次开通或者联系客服";
 4 NSString *title = @"400-8591-200";
 5 NSString *leftActionStr = @"呼叫";
 6 NSString *rightActionStr = @"继续开通";
 7 UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
 8 //改变title的大小和颜色
 9 NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc] initWithString:title];
10 [titleAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:(36/2)*KWidth_Scale] range:NSMakeRange(0, title.length)];
11 [titleAtt addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x00abea) range:NSMakeRange(0, title.length)];
12 [alertController setValue:titleAtt forKey:@"attributedTitle"];
13 //改变message的大小和颜色
14 NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:message];
15 [messageAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:(24/2)*KWidth_Scale] range:NSMakeRange(0, message.length)];
16 [messageAtt addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x666666) range:NSMakeRange(0, message.length)];
17 [alertController setValue:messageAtt forKey:@"attributedMessage"];
18 
19 UIAlertAction *alertActionCall = [UIAlertAction actionWithTitle:leftActionStr style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
20     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://400-8591-200"]];
21 }];
22 [alertController addAction:alertActionCall];
23 [alertActionCall setValue:UIColorFromRGB(0x00abea) forKey:@"titleTextColor"];
24 kWeakSelf(weakSelf);
25 UIAlertAction *alertActionContinue = [UIAlertAction actionWithTitle:rightActionStr style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
26     [weakSelf oprDrugStoreStatu:@"0"];
27 }];
28 [alertController addAction:alertActionContinue];
29 [alertActionContinue setValue:[UIColor blackColor] forKey:@"titleTextColor"];
30 [self presentViewController:alertController animated:YES completion:nil];
31 
32 
33 
34 
35 /**************** UIAlertControllerStyleActionSheet *************************/
36 NSString *title = [NSString stringWithFormat:@"将患者\"%@\"删除,同时删除与该联系人的聊天记录", self.user.patientName];
37 UIAlertController *alertSheet = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet];
38 
39 UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
40 [cancel setValue:UIColorFromRGB(0x666666) forKey:@"titleTextColor"];
41 [alertSheet addAction:cancel];
42 
43 UIAlertAction *certain = [UIAlertAction actionWithTitle:@"删除联系人" style:UIAlertActionStyleDestructive handler:
44                           ^(UIAlertAction * _Nonnull action) {
45                               NSLog(@"执行删除操作,这里应该接着请求删除接口......");
46                           }];
47 [alertSheet addAction:certain];
48 [self presentViewController:alertSheet animated:YES completion:nil];

 

自定义alert弹框

标签:round   present   nbsp   弹框   联系人   scale   tle   key   聊天   

原文地址:http://www.cnblogs.com/jingxin1992/p/7700983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!