調(diào)用代碼:
```
[self customAlertViewWithTitle:nil Message:@"微信號已成功復(fù)制,請前往微信搜索添加" 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];
?? ? ? ? //調(diào)起微信
?? ? }];
?? ? //修改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顏色,字體大小的代碼解注釋就可以了。
運行效果如下:

就到這里啦~