1.添加一個(gè)輸入框
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個(gè)輸入框夺欲;
UITextField *TextField = alertController.textFields.firstObject;
NSString *moneyStr = [NSString stringWithFormat:@"%.2lf",[TextField.text doubleValue]];
if ([moneyStr doubleValue] >= [goods.salePrice doubleValue]) {
kShowInfo(@"稅差不能大于等于含稅價(jià)格");
return;
}
NSMutableDictionary * dict = [NSMutableDictionary dictionary];
dict[@"goodsId"] = [GlobelConfig getNullStr:goods.ID];
dict[@"taxPremium"] = moneyStr;
[self changeTaxPremium:dict];
}]];
//定義第一個(gè)輸入框烟零;
[alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
textField.placeholder = @"請(qǐng)輸入稅差";
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:@"報(bào)款總金額:¥%.2f\n",totalReportAmount] chooseText:[NSString stringWithFormat:@"¥%.2f",totalReportAmount] color:[UIColor redColor] fontSize:16.0];
NSMutableAttributedString * totalGoodsText = [GlobelConfig setTextColor:[NSString stringWithFormat:@"商品合計(jì)報(bào)款:¥%.2f\n",totalGoodsPaidAmount] chooseText:[NSString stringWithFormat:@"¥%.2f",totalGoodsPaidAmount] color:[UIColor redColor] fontSize:16.0];
NSMutableAttributedString * totalFreightText = [GlobelConfig setTextColor:[NSString stringWithFormat:@"運(yùn)輸合計(jì)報(bào)款:¥%.2f\n",totalFreightPaidAmount] chooseText:[NSString stringWithFormat:@"¥%.2f",totalFreightPaidAmount] color:[UIColor redColor] fontSize:16.0];
NSMutableAttributedString * totalInterestText = [GlobelConfig setTextColor:[NSString stringWithFormat:@"利息合計(jì)報(bào)款:¥%.2f\n",totalInterestPaidAmount] chooseText:[NSString stringWithFormat:@"¥%.2f",totalInterestPaidAmount] color:[UIColor redColor] fontSize:16.0];
NSMutableAttributedString * residueUsableText = [GlobelConfig setTextColor:[NSString stringWithFormat:@"剩余可用金額:¥%.2f\n確定繼續(xù)嗎抒倚?",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結(jié)合使用)
// 修改字體的顏色
[nan setValue:[UIColor yellowColor] forKey:@"_titleTextColor"];