系統默認的字體是黑色,按鈕顏色是藍色或者紅色的,我們怎樣自定義字體呢
Codeing Show
UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"提示" message:@"確認退出登錄?" preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { NSLog(@"點擊了Cancel"); [alertVC dismissViewControllerAnimated:YES completion:nil]; }]; UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSLog(@"點擊了OK"); [[NSUserDefaults standardUserDefaults] setObject:nil forKey:kLoginUserKey]; [alertVC dismissViewControllerAnimated:YES completion:nil]; }]; //修改title NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:@"提示"]; [alertControllerStr addAttribute:NSForegroundColorAttributeName value:kMainTextColor 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:@"確認退出登錄?"]; [alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:kSubTextColor range:NSRangeFromString(@"確認退出登錄?")]; [alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:13] range:NSRangeFromString(@"確認退出登錄?")]; [alertVC setValue:alertControllerMessageStr forKey:@"attributedMessage"]; //修改按鈕字體顏色 [cancelAction setValue:kGreenColor forKey:@"titleTextColor"]; [okAction setValue:kGreenColor forKey:@"titleTextColor"]; [alertVC addAction:cancelAction]; [alertVC addAction:okAction]; [self presentViewController:alertVC animated:YES completion:nil];
這里的kGreenColor 等是我自定義的顏色,換成自己的字體顏色即可
以上這篇iOS 修改alertViewController彈框的字體顏色及字體的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答