gpt4 book ai didi

ios - 是否可以编辑 UIAlertAction 标题字体大小和样式?

转载 作者:行者123 更新时间:2023-12-03 17:43:03 24 4
gpt4 key购买 nike

现在 iOS8 已弃用 UIActionsheetUIAlertview在 iOS7 上工作的自定义不再生效。到目前为止,我知道的唯一自定义是色调颜色。而我需要的是更改标题的字体大小和样式,而我在新的 UIAlertAction 中没有找到这样做的任何方法。 .

Already referred to this但我仍然希望有一种方法可以至少更改标题大小和字体。

为您提供我的一些代码 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

导入该文件后,您需要调用以下函数。
UILabel * appearanceLabel = [UILabel appearanceWhenContainedIn:UIAlertController.class, nil];
[appearanceLabel setAppearanceFont:yourDesireFont]];

上面的代码在颜色和字体上进行了测试。并且仅对 iOS8 或更高版本有效。

关于ios - 是否可以编辑 UIAlertAction 标题字体大小和样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31497218/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com