UIAlertController 用 KVC 和富文本自定义 标题和信息 的颜色和字体

@Manajay:我的 github 博客

//富文本属性 
 NSMutableAttributedString *attributedTitle = [[NSMutableAttributedString alloc] initWithString:@"提交成功!" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor darkGrayColor]}];
    
   //富文本属性 
 NSMutableAttributedString *attributedMessage= [[NSMutableAttributedString alloc] initWithString:@"结算钱款会在2到3个工作日内转到您的收款帐号,请您注意查收哦!" attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSForegroundColorAttributeName:[UIColor darkGrayColor]}];
    
    // 在 viewDidLoad 中创建
    self.alertVC = [UIAlertController alertControllerWithTitle:attributedTitle.string message:attributedMessage.string preferredStyle:UIAlertControllerStyleAlert];
    // 用 KVC 修改其 没有暴露出来的 
    [self.alertVC setValue:attributedTitle forKey:@"attributedTitle"];
    [self.alertVC setValue:attributedMessage forKey:@"attributedMessage"];
    [self.alertVC addAction:[UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        //用控制器  跳转到下一个控制器
        // Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior
    }]];

你可能感兴趣的:(UIAlertController 用 KVC 和富文本自定义 标题和信息 的颜色和字体)