如何设置UIAlertAction提示信息的部分字体的颜色

NSString *message = NSLocalizedString ( @"新版本手机办公上线,请前往http://www.baidu.com下载安装访问,旧版系统即日起停用。给您带来的不便,敬请谅解!" , nil );
NSString *title = @"尊敬的各位领导同事\n" ;

UIAlertController *alertController = [ UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];

//改变message的大小和颜色
NSMutableAttributedString *messageAtt = [[ NSMutableAttributedString alloc] initWithString:message];


  //设置需要改变颜色字体的开始位置 和结束位置
[messageAtt addAttribute : NSForegroundColorAttributeName value:[UIColorblueColor] range:NSMakeRange(13, 20)];
 [alertController setValue:messageAtt forKey:@"attributedMessage"];
   
  UIAlertAction *alertAction = [ UIAlertAction actionWithTitle:NSLocalizedString(@"前往",nil) style:UIAlertActionStyleCancelhandler:nil];
[alertController addAction :alertAction];
[ self . window . rootViewController presentViewController:alertController animated:YEScompletion:nil];
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要改变 UIAlertAction字体大小,您可以使用富文本属性来设置 UIAlertAction 的标题的字体大小。下面是一个示例代码: ```objective-c UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"标题" message:@"消息" preferredStyle:UIAlertControllerStyleAlert]; UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { // 点击确定按钮后的处理逻辑 }]; // 创建富文本属性字典 NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:20]}; // 设置字体大小为 20 // 使用富文本属性设置 UIAlertAction 的标题字体大小 NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:@"确定" attributes:attributes]; [action setValue:attributedTitle forKey:@"attributedTitle"]; [alertController addAction:action]; [self presentViewController:alertController animated:YES completion:nil]; ``` 在上面的示例中,我们首先创建了一个 UIAlertController,并设置其标题和消息。然后,我们创建了一个 UIAlertAction,并设置其标题为 "确定",并指定了点击按钮后的处理逻辑。 接下来,我们创建了一个富文本属性字典,其中包含了一个字体大小为 20 的字体属性。然后,使用这个富文本属性设置 UIAlertAction 的标题字体大小。我们将富文本标题设置为 "确定"。 最后,我们将 UIAlertAction 添加到 UIAlertController 中,并通过 presentViewController 方法来显示 UIAlertController。 这样,您就可以改变 UIAlertAction字体大小了。请注意,使用私有键 "attributedTitle" 来设置富文本标题是一种非官方的方法,可能会在未来的 iOS 版本中发生变化。如果有其他问题,请随时提问!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值