我使用UIAlertControllerStyleActionSheet样式展示了UIAlertController。使用XCode 13在iPhone 12上构建时,UIAlertController的标题和消息无法正常工作,但在其他设备上可以正常工作。同样的代码先前在iPhone 12上也能正常工作。
-(void)alertSheetUI{
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Static Title" message:@"Static Message" preferredStyle:UIAlertControllerStyleActionSheet];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Data 1" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Data 2" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Data 3" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
[[[UIApplication sharedApplication] delegate].window.rootViewController dismissViewControllerAnimated:YES completion:^{
}];
}]];
[[[UIApplication sharedApplication] delegate].window.rootViewController presentViewController:actionSheet animated:NO completion:nil];
});}
iPhone 12
视图层次结构显示标题和消息为白色。因此,只有标题和消息不可见。我尝试使用下面的代码将标题和消息设置为绿色,并使用属性文本。但在其他设备上,标题和消息颜色未更新。其他设备显示为灰色。
更新后的代码
-(void)alertSheetUI{
dispatch_async(dispatch_get_main_queue(), ^{
NSString * string = @"Static Title";
NSMutableAttributedString * attrString = [[NSMutableAttributedString alloc] initWithString:@"Static Title"];
[attrString addAttribute:NSForegroundColorAttributeName
value:[UIColor greenColor] range:NSMakeRange(0, [string length])];
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Static Title" message:@"Static Message" preferredStyle:UIAlertControllerStyleActionSheet];
[actionSheet setValue:attrString forKey:@"attributedTitle"];
[actionSheet setValue:attrString forKey:@"attributedMessage"];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Data 1" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Data 2" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Data 3" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}]];
[actionSheet addAction:[UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
[[[UIApplication sharedApplication] delegate].window.rootViewController dismissViewControllerAnimated:YES completion:^{
}];
}]];
[[[UIApplication sharedApplication] delegate].window.rootViewController presentViewController:actionSheet animated:NO completion:nil];
});}
alertSheetUI
时 - Anbu.Karthik