iOS開發(fā) 系統(tǒng)彈框改變Title、Message、各個按鈕的顏色,字體大小

調(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顏色,字體大小的代碼解注釋就可以了。

運行效果如下:


效果圖,這里沒有寫title

就到這里啦~

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容