ios - 如何在 UIAlertController 中更改 UIAlertAction 的字体大小和颜色

标签 ios iphone uialertcontroller uialertaction

enter image description here

上图中“Done”、“Some Other action”如何改变字体大小和颜色? 以及如何更改“title”和“message”的字体大小和颜色?

谢谢。

最佳答案

这是来自另一个堆栈溢出帖子,但似乎工作正常。 Post found here.

UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"Dont care what goes here, since we're about to change below" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
NSMutableAttributedString *hogan = [[NSMutableAttributedString alloc] initWithString:@"Presenting the great... Hulk Hogan!"];
[hogan addAttribute:NSFontAttributeName
          value:[UIFont systemFontOfSize:50.0]
          range:NSMakeRange(24, 11)];
[alertVC setValue:hogan forKey:@"attributedTitle"];



UIAlertAction *button = [UIAlertAction actionWithTitle:@"Label text" 
                                    style:UIAlertActionStyleDefault
                                    handler:^(UIAlertAction *action){
                                                //add code to make something happen once tapped
}];
UIImage *accessoryImage = [UIImage imageNamed:@"someImage"];
[button setValue:accessoryImage forKey:@"image"];

要使用以下内容更改文本的颜色,请将其添加到行设置之前 [alertVC setValue:hogan forKey:@"attributedTitle"];

[hogan addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,35)];

关于ios - 如何在 UIAlertController 中更改 UIAlertAction 的字体大小和颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29382034/

相关文章:

iOS/ cocoa : UIAlertView throwing EXC_BAD_ACCESS

swift : OverlayView that appears at the bottom of the screen

ios - 无法将两个 AlertController 放在同一个 VC 上

ios - 更改推送通知系统的配置文件

ios - 使用 HTML 文件初始化 NSAttributedString 将 HTTP 链接解析为文件 URL

ios - 如何将导航 Controller 添加到不是主视图的 View ?

iphone - 如何使 Autoresize 属性在 Xcode 4.3 中工作?

iphone - 如何在 iOS 的一个证书中分发两个应用程序?

objective-c - 仅停止 iPhone 屏幕在 Universal Xcode 6 项目中旋转

ios - 在 iOS 的 UIAlertController 中添加自定义 View