Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the Font of UIAlertAction in Swift [duplicate]

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.

Providing you some of my code for 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];
like image 821
Teffi Avatar asked Nov 21 '22 11:11

Teffi


1 Answers

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

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]]; 

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

like image 173
Muhammad Ali Yousaf Avatar answered Dec 13 '22 08:12

Muhammad Ali Yousaf