【发布时间】:2021-12-29 06:23:54
【问题描述】:
我用 UIAlertControllerStyleActionSheet 样式显示了 UIAlertController。使用 XCode 13 UIAlertController 构建时,标题和消息在 iPhone 12 上不起作用。它在其他设备上起作用。之前在 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];
});}
【问题讨论】:
-
用模拟器试一次
-
运行设备的系统版本是多少?图片似乎您已经自定义了 UIAlertController 的外观?
-
@Anbu.Karthik 在 iPhone 12 模拟器上运行良好
-
@childrenOurFuture 设备版本是 iOS 15。我没有自定义 UIAlertController UI。看起来这仅在 iPhone 12 上使用提到的代码。已添加 iPhone SE 屏幕截图以供参考。
-
Tint 颜色/UIAppearance 自定义完成了吗?文字在白色背景上看起来是“白色的”,所以不可见。如果您检查(例如使用调试视图层次结构),文本存在,对吗?
标签: ios objective-c uialertcontroller xcode13