UIAlertController根据keypath修改属性

根据keypath修改控件属性

        UIAlertController *alertC = [UIAlertController alertControllerWithTitle:@"吹牛逼" message:[NSString stringWithFormat:@" \n吹牛逼  ¥ %@ 元一次", self.donatedAmount] preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *action_cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        }];
        UIAlertAction *action_sure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [self useJkbWalletBlancePayDonate];
        }];
        
        //修改标题字体属性
        NSMutableAttributedString * titleAttStr = [[NSMutableAttributedString alloc] initWithString:@"支付"];
        [titleAttStr setAttributes:@{NSFontAttributeName : FONT_BOLD(16.0), NSForegroundColorAttributeName : ColorFromHex(@"4a4a4a")} range:NSMakeRange(0, titleAttStr.length)];
        [alertC setValue:titleAttStr forKey:@"attributedTitle"];

        // 修改message字体属性
        NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
        style.lineSpacing = 10;
        style.alignment = NSTextAlignmentCenter;
        NSMutableAttributedString * messageAttStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"牛逼余额支付\n¥ %@ 元", self.donatedAmount]];
        [messageAttStr setAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:13], NSForegroundColorAttributeName : ColorFromHex(@"4a4a4a"), NSParagraphStyleAttributeName : style} range:NSMakeRange(0, 7)];
        [messageAttStr setAttributes:@{NSFontAttributeName : [UIFont boldSystemFontOfSize:25],  NSForegroundColorAttributeName : ColorFromHex(@"4a4a4a"), NSParagraphStyleAttributeName : style} range:NSMakeRange(7, messageAttStr.length - 7)];
        [alertC setValue:messageAttStr forKey:@"attributedMessage"];
        
// 修改按钮属性
        [action_sure setValue:ColorFromHex(@"96b057") forKey:@"titleTextColor"];
        [action_cancle setValue:ColorFromHex(@"9b9b9b") forKey:@"titleTextColor"];
        
        [alertC addAction:action_cancle];
        [alertC addAction:action_sure];
        
        [self presentViewController:alertC animated:YES completion:nil];

你可能感兴趣的:(UIAlertController根据keypath修改属性)