自定义alert弹框

时间:2023-03-09 08:46:34
自定义alert弹框
 /**************** UIAlertControllerStyleAlert *************************/
/*创建一个 可以自定义文字颜色和字体大小的IAlertView*/
NSString *message = @"开通失败,请再次开通或者联系客服";
NSString *title = @"400-8591-200";
NSString *leftActionStr = @"呼叫";
NSString *rightActionStr = @"继续开通";
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
//改变title的大小和颜色
NSMutableAttributedString *titleAtt = [[NSMutableAttributedString alloc] initWithString:title];
[titleAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:(/)*KWidth_Scale] range:NSMakeRange(, title.length)];
[titleAtt addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x00abea) range:NSMakeRange(, title.length)];
[alertController setValue:titleAtt forKey:@"attributedTitle"];
//改变message的大小和颜色
NSMutableAttributedString *messageAtt = [[NSMutableAttributedString alloc] initWithString:message];
[messageAtt addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:(/)*KWidth_Scale] range:NSMakeRange(, message.length)];
[messageAtt addAttribute:NSForegroundColorAttributeName value:UIColorFromRGB(0x666666) range:NSMakeRange(, message.length)];
[alertController setValue:messageAtt forKey:@"attributedMessage"]; UIAlertAction *alertActionCall = [UIAlertAction actionWithTitle:leftActionStr style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://400-8591-200"]];
}];
[alertController addAction:alertActionCall];
[alertActionCall setValue:UIColorFromRGB(0x00abea) forKey:@"titleTextColor"];
kWeakSelf(weakSelf);
UIAlertAction *alertActionContinue = [UIAlertAction actionWithTitle:rightActionStr style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[weakSelf oprDrugStoreStatu:@""];
}];
[alertController addAction:alertActionContinue];
[alertActionContinue setValue:[UIColor blackColor] forKey:@"titleTextColor"];
[self presentViewController:alertController animated:YES completion:nil]; /**************** UIAlertControllerStyleActionSheet *************************/
NSString *title = [NSString stringWithFormat:@"将患者\"%@\"删除,同时删除与该联系人的聊天记录", self.user.patientName];
UIAlertController *alertSheet = [UIAlertController alertControllerWithTitle:title message:nil preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
[cancel setValue:UIColorFromRGB(0x666666) forKey:@"titleTextColor"];
[alertSheet addAction:cancel]; UIAlertAction *certain = [UIAlertAction actionWithTitle:@"删除联系人" style:UIAlertActionStyleDestructive handler:
^(UIAlertAction * _Nonnull action) {
NSLog(@"执行删除操作,这里应该接着请求删除接口......");
}];
[alertSheet addAction:certain];
[self presentViewController:alertSheet animated:YES completion:nil];