是否有可能编辑UIAlertAction标题的字体大小和风格?

现在,iOS8弃用的UIActionsheetUIAlertview在iOS7上工作的定制不再生效。 到目前为止,我知道唯一的定制是色彩的颜色。 而我所需要的是改变标题的字体大小和样式,我还没有find任何方式来使用新的UIAlertAction

已经提到这个,但我仍然希望有一种方法来改变至less标题大小和字体。

为您提供一些UIAlertAction代码

 UIAlertController * alertActionSheetController = [UIAlertController alertControllerWithTitle:@"Settings" message:@"" preferredStyle:UIAlertControllerStyleActionSheet]; UIAlertAction * aboutTheAppAction = [UIAlertAction actionWithTitle:@"About the App" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){ NSLog(@"About the app"); [self openAbout]; }]; [alertActionSheetController addAction:aboutTheAppAction]; [self presentViewController:alertActionSheetController animated:YES completion:nil]; 

您可以更改UIAlertAction的字体和颜色。 首先你需要添加UILabel类别

 @interface UILabel (FontAppearance) @property (nonatomic, copy) UIFont * appearanceFont UI_APPEARANCE_SELECTOR; @end @implementation UILabel (FontAppearance) -(void)setAppearanceFont:(UIFont *)font { if (font) [self setFont:font]; } -(UIFont *)appearanceFont { return self.font; } @end 

类别文件也上传到以下URL https://www.dropbox.com/s/em91fh00fv3ut4h/Archive.zip?dl=0

导入该文件后,您需要调用以下function。

 UILabel * appearanceLabel = [UILabel appearanceWhenContainedIn:UIAlertController.class, nil]; [appearanceLabel setAppearanceFont:yourDesireFont]]; 

以上代码在颜色和字体上进行了testing。 这只会对iOS8或更高版本有效。

可以使用私有API更改警报操作的字体。 它可能会让你的应用程序被拒绝,我还没有试图提交这样的代码。

 let alert = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet) let action = UIAlertAction(title: "Some title", style: .Default, handler: nil)let attributedText = NSMutableAttributedString(string: "Some title") let range = NSRange(location: 0, length: attributedText.length) attributedText.addAttribute(NSKernAttributeName, value: 1.5, range: range) attributedText.addAttribute(NSFontAttributeName, value: UIFont(name: "ProximaNova-Semibold", size: 20.0)!, range: range) alert.addAction(action) presentViewController(alert, animated: true, completion: nil) // this has to be set after presenting the alert, otherwise the internal property __representer is nil guard let label = action.valueForKey("__representer")?.valueForKey("label") as? UILabel else { return } label.attributedText = attributedText