Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

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

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];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...