iOS开发 系统弹框改变Title、Message、各个按钮的颜色,字体大小

调用代码:

```

[self customAlertViewWithTitle:nil Message:@"微信号已成功复制,请前往微信搜索添加" CancelBtnTiele:@"稍后再去" SureButtonTitle:@"去添加"];

```

核心代码:

```

-(void)customAlertViewWithTitle:(NSString*)title Message:(NSString*)msg CancelBtnTiele:(NSString*)cancelTitle SureButtonTitle:(NSString*)sureTitle{

    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:title message:msg preferredStyle:(UIAlertControllerStyleAlert)];

     UIAlertAction*cancelAction = [UIAlertActionactionWithTitle:cancelTitlestyle:UIAlertActionStyleCancelhandler:^(UIAlertAction*_Nonnullaction) {


     //[alertVC dismissViewControllerAnimated:YES completion:nil];

     }];

     UIAlertAction*okAction = [UIAlertActionactionWithTitle:sureTitlestyle:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {


     //[alertVC dismissViewControllerAnimated:YES completion:nil];

         //调起微信

     }];

     //修改title

//    NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:title];

//    [alertControllerStr addAttribute:NSForegroundColorAttributeName value:kBlackColor range:NSMakeRange(0, 2)];

//    [alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15] range:NSMakeRange(0, 2)];

//    [alertVC setValue:alertControllerStr forKey:@"attributedTitle"];

     //修改message

     NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:msg];

     [alertControllerMessageStraddAttribute:NSForegroundColorAttributeNamevalue:kBlackColorrange:NSRangeFromString(msg)];

     [alertControllerMessageStraddAttribute:NSFontAttributeNamevalue: [UIFont systemFontOfSize:18] range:NSRangeFromString(msg)];

     [alertVCsetValue:alertControllerMessageStrforKey:@"attributedMessage"];

     //修改按钮字体颜色

     [cancelActionsetValue:kLightGrayColorforKey:@"titleTextColor"];

     [okActionsetValue:[UIColor colorWithHexString:@"F57A00"] forKey:@"titleTextColor"];

     [alertVCaddAction:cancelAction];

     [alertVCaddAction:okAction];

     [self presentViewController:alertVC animated:YES completion:nil];

}

```

这里我去掉了title,如果需要title,直接写上title,把核心代码块里面注释的更改title颜色,字体大小的代码解注释就可以了。

运行效果如下:


效果图,这里没有写title

就到这里啦~

你可能感兴趣的:(iOS开发 系统弹框改变Title、Message、各个按钮的颜色,字体大小)