iOS UIAlertController

1.添加一个输入框

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"修改税差(元/吨)" message:@"" preferredStyle:UIAlertControllerStyleAlert];
        //增加取消按钮
        [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];
        //增加确定按钮
        [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            //获取第1个输入框;
            UITextField *TextField = alertController.textFields.firstObject;
            NSString *moneyStr = [NSString stringWithFormat:@"%.2lf",[TextField.text doubleValue]];
            if ([moneyStr doubleValue] >= [goods.salePrice doubleValue]) {
                kShowInfo(@"税差不能大于等于含税价格");
                return;
            }

            NSMutableDictionary * dict = [NSMutableDictionary dictionary];
            dict[@"goodsId"] = [GlobelConfig getNullStr:goods.ID];
            dict[@"taxPremium"] = moneyStr;
            [self changeTaxPremium:dict];
        }]];

        //定义第一个输入框;
        [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
            textField.placeholder = @"请输入税差";
            textField.keyboardType = UIKeyboardTypeDecimalPad;
            textField.text = [NSString stringWithFormat:@"%.2lf",[goods.taxPremium doubleValue]];
        }];

        [self presentViewController:alertController animated:true completion:nil];

2.自定义UIAlertController的message

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:alertTitle message:@"" preferredStyle:UIAlertControllerStyleAlert];
    // 增加取消按钮;
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:nil]];
    // 增加确定按钮;
    [alertController addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (self.relatePlanOrderGoodsBlock) {
            self.relatePlanOrderGoodsBlock(selectArray);
            [self.navigationController popViewControllerAnimated:YES];
        }
    }]];
    
    NSMutableAttributedString * totalReportText = [GlobelConfig setTextColor:[NSString stringWithFormat:@"报款总金额:¥%.2f\n",totalReportAmount] chooseText:[NSString stringWithFormat:@"¥%.2f",totalReportAmount] color:[UIColor redColor] fontSize:16.0];
    NSMutableAttributedString * totalGoodsText = [GlobelConfig setTextColor:[NSString stringWithFormat:@"商品合计报款:¥%.2f\n",totalGoodsPaidAmount] chooseText:[NSString stringWithFormat:@"¥%.2f",totalGoodsPaidAmount] color:[UIColor redColor] fontSize:16.0];
    NSMutableAttributedString * totalFreightText = [GlobelConfig setTextColor:[NSString stringWithFormat:@"运输合计报款:¥%.2f\n",totalFreightPaidAmount] chooseText:[NSString stringWithFormat:@"¥%.2f",totalFreightPaidAmount] color:[UIColor redColor] fontSize:16.0];
    NSMutableAttributedString * totalInterestText = [GlobelConfig setTextColor:[NSString stringWithFormat:@"利息合计报款:¥%.2f\n",totalInterestPaidAmount] chooseText:[NSString stringWithFormat:@"¥%.2f",totalInterestPaidAmount] color:[UIColor redColor] fontSize:16.0];
    NSMutableAttributedString * residueUsableText = [GlobelConfig setTextColor:[NSString stringWithFormat:@"剩余可用金额:¥%.2f\n确定继续吗?",residueUsablePrice] chooseText:[NSString stringWithFormat:@"¥%.2f",residueUsablePrice] color:[UIColor redColor] fontSize:16.0];
    
    NSMutableAttributedString * endString = [[NSMutableAttributedString alloc]init];
    [endString appendAttributedString:totalReportText];
    [endString appendAttributedString:totalGoodsText];
    [endString appendAttributedString:totalFreightText];
    [endString appendAttributedString:totalInterestText];
    [endString appendAttributedString:residueUsableText];
    
    [alertController setValue:endString forKey:@"attributedMessage"];
   
    [self presentViewController:alertController animated:true completion:nil];

3.自定义UIAlertController的title

 [alert setValue:attibuedString forKey:@"attributedTitle"];

4.修改action字体的颜色(需要runtime与KVC结合使用)

// 修改字体的颜色
[nan setValue:[UIColor yellowColor] forKey:@"_titleTextColor"];

你可能感兴趣的:(iOS UIAlertController)