是否可以编辑UIAlertAction标题字体大小和样式? [英] Is it possible to edit UIAlertAction title font size and style?

查看:2876
本文介绍了是否可以编辑UIAlertAction标题字体大小和样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,iOS8已弃用 UIActionsheet UIAlertview ,iOS7上的自定义功能不再生效。到目前为止,我所知道的唯一定制是色彩。我需要的是改变标题的字体大小和样式,我没有找到任何方式使用新的 UIAlertAction

Now that iOS8 deprecated UIActionsheet and UIAlertview the customization working on iOS7 is not taking effect anymore. So far the only customization I'm aware is the tint color. And what I need is changing the title's font size and style which I haven't found any way of doing so with the new UIAlertAction.

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

Already referred to this but I'm still hoping there's a way to change at least the title size and font.

为我提供一些 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类别

You can change UIAlertAction's Font and color. First you need to add UILabel Category

@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

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

Category File is also Uploaded on following URL https://www.dropbox.com/s/em91fh00fv3ut4h/Archive.zip?dl=0

导入该文件后需要调用以下函数。

After importing That file You need to call following function.

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

以上代码在颜色和字体上进行测试。这只适用于iOS8或更高版本。

Above code is tested on Color and font. and that will only valid for iOS8 or greater.

这篇关于是否可以编辑UIAlertAction标题字体大小和样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆