【发布时间】:2017-09-06 12:04:16
【问题描述】:
我想更改UIAlertController UIAlertAction TextColor 并在用户选择操作时显示复选标记图像。
我可以正常显示UIAlertController。但我怎样才能做到这一点?
任何人都可以建议我或帮助我这样做吗? 谢谢
【问题讨论】:
标签: ios uialertcontroller uialertaction
我想更改UIAlertController UIAlertAction TextColor 并在用户选择操作时显示复选标记图像。
我可以正常显示UIAlertController。但我怎样才能做到这一点?
任何人都可以建议我或帮助我这样做吗? 谢谢
【问题讨论】:
标签: ios uialertcontroller uialertaction
不可能/不建议覆盖UIAlertAction textcolor。您必须创建自己的视图并根据需要呈现它。有一些第三方库可以帮助您实现您想要的。
【讨论】:
试试这个 无需使用任何 3rdParty 库
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel action") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action){
NSLog(@"Cancle Tapped");
[alertController dismissViewControllerAnimated:YES completion:nil];
}];
[alertController addAction:cancelAction];
UIAlertAction *yesAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"YES", @"YES action") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
NSLog(@"Yes Button Tapped");
}];
// Add CheckMark And Change CheckMark Color
[yesAction setValue:YOUR_COLOUR forKey:@"titleTextColor"];
[yesAction setValue:YOUR_COLOUR forKey:@"imageTintColor"];
[alertController addAction:yesAction];
UIAlertAction *noAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"NO", @"NO action") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action){
}];
// Add CheckMark And Change CheckMark Color
[noAction setValue:YOUR_COLOUR forKey:@"titleTextColor"];
[noAction setValue:YOUR_COLOUR forKey:@"imageTintColor"];
[alertController addAction:noAction];
[self presentViewController:alertController animated:YES completion:nil];
如果你想默认设置任何带有 CheckMark 的按钮,而不是添加这个。
[yesAction setValue:@true forKey:@"checked"];
【讨论】: