iOS 修改alertViewController弹框的字体颜色及字体的方法
系统默认的字体是黑色,按钮颜色是蓝色或者红色的,我们怎样自定义字体呢
CodeingShow
UIAlertController*alertVC=[UIAlertControlleralertControllerWithTitle:@"提示"message:@"确认退出登录?"preferredStyle:(UIAlertControllerStyleAlert)]; UIAlertAction*cancelAction=[UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction*_Nonnullaction){ NSLog(@"点击了Cancel"); [alertVCdismissViewControllerAnimated:YEScompletion:nil]; }]; UIAlertAction*okAction=[UIAlertActionactionWithTitle:@"确定"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction){ NSLog(@"点击了OK"); [[NSUserDefaultsstandardUserDefaults]setObject:nilforKey:kLoginUserKey]; [alertVCdismissViewControllerAnimated:YEScompletion:nil]; }]; //修改title NSMutableAttributedString*alertControllerStr=[[NSMutableAttributedStringalloc]initWithString:@"提示"]; [alertControllerStraddAttribute:NSForegroundColorAttributeNamevalue:kMainTextColorrange:NSMakeRange(0,2)]; [alertControllerStraddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:15]range:NSMakeRange(0,2)]; [alertVCsetValue:alertControllerStrforKey:@"attributedTitle"]; //修改message NSMutableAttributedString*alertControllerMessageStr=[[NSMutableAttributedStringalloc]initWithString:@"确认退出登录?"]; [alertControllerMessageStraddAttribute:NSForegroundColorAttributeNamevalue:kSubTextColorrange:NSRangeFromString(@"确认退出登录?")]; [alertControllerMessageStraddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:13]range:NSRangeFromString(@"确认退出登录?")]; [alertVCsetValue:alertControllerMessageStrforKey:@"attributedMessage"]; //修改按钮字体颜色 [cancelActionsetValue:kGreenColorforKey:@"titleTextColor"]; [okActionsetValue:kGreenColorforKey:@"titleTextColor"]; [alertVCaddAction:cancelAction]; [alertVCaddAction:okAction]; [selfpresentViewController:alertVCanimated:YEScompletion:nil];
这里的kGreenColor等是我自定义的颜色,换成自己的字体颜色即可
以上这篇iOS修改alertViewController弹框的字体颜色及字体的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。