iOS 13 UIAlertController - Color change in attributedMessage and attributedTitle doesn't work

时光总嘲笑我的痴心妄想 提交于 2020-01-05 06:44:05

问题


Color change in attributedMessage and attributedTitle doesn't work. Is there a solution for it? Works well on iOS 12 but no longer works on iOS 13. What can be done or is there a solution or a modification?

Here's the full snippet:

NSString *title=NSLocalizedString(@"Title",nil);
NSString *message=NSLocalizedString(@"Message",nil);

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
[alertController addAction:({
    UIAlertAction *action0 = [UIAlertAction actionWithTitle:NSLocalizedString(@"Other1",nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action0) {
        NSLog(@"OK1");


    }];
    [action0 setValue:[UIColor lightGrayColor] forKey:@"titleTextColor"];
    action0;
})];
[alertController addAction:({
    UIAlertAction *action = [UIAlertAction actionWithTitle:NSLocalizedString(@"Other2",nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
        NSLog(@"OK2");


    }];
    [action setValue:[UIColor lightGrayColor] forKey:@"titleTextColor"];
    action;
})];
[alertController addAction:({
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel",nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action2) {

    }];
    [action2 setValue:[UIColor orangeColor] forKey:@"titleTextColor"];
    action2;
})];

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle setAlignment:NSTextAlignmentCenter];
NSMutableAttributedString *titleText;
titleText = [[NSMutableAttributedString alloc]
             initWithString:title
             attributes:@{NSParagraphStyleAttributeName: paragraphStyle,
                          NSFontAttributeName : [UIFont boldSystemFontOfSize:17],
                          NSForegroundColorAttributeName :[UIColor whiteColor]
                          }];
NSMutableParagraphStyle *paragraphStyle2 = [[NSMutableParagraphStyle alloc] init];
[paragraphStyle2 setAlignment:NSTextAlignmentCenter];
NSMutableAttributedString *messageText;
messageText = [[NSMutableAttributedString alloc]
               initWithString:message
               attributes:@{NSParagraphStyleAttributeName: paragraphStyle2,
                            NSFontAttributeName : [UIFont boldSystemFontOfSize:14],
                            NSForegroundColorAttributeName : [UIColor lightTextColor]
                            }];

[alertController setValue:titleText  forKey:@"attributedTitle"];
[alertController setValue:messageText forKey:@"attributedMessage"];


[self presentViewController:alertController animated:YES completion:nil];

来源:https://stackoverflow.com/questions/58224830/ios-13-uialertcontroller-color-change-in-attributedmessage-and-attributedtitle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!