如何更改 UIAlertController UIAlertAction 颜色并添加复选标记?
How to Change UIAlertController UIAlertAction Colour and add Checkmark Sign?
我想更改 UIAlertController
UIAlertAction
TextColor 并在用户 Select 执行操作时显示复选标记图像。
我可以正常显示UIAlertController
。但我怎样才能做到这一点?
任何人都可以建议我或帮助我这样做吗?
谢谢
不是possible/advisable覆盖UIAlertAction
textcolor
。您将必须创建自己的视图并根据您的视图呈现它 needs.There 一些第 3 方库可以帮助您实现您想要的。
试试这个 不需要使用任何 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];
并且如果您想默认设置带有复选标记的任何按钮而不是添加此。
[yesAction setValue:@true forKey:@"checked"];
我想更改 UIAlertController
UIAlertAction
TextColor 并在用户 Select 执行操作时显示复选标记图像。
我可以正常显示UIAlertController
。但我怎样才能做到这一点?
任何人都可以建议我或帮助我这样做吗? 谢谢
不是possible/advisable覆盖UIAlertAction
textcolor
。您将必须创建自己的视图并根据您的视图呈现它 needs.There 一些第 3 方库可以帮助您实现您想要的。
试试这个 不需要使用任何 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];
并且如果您想默认设置带有复选标记的任何按钮而不是添加此。
[yesAction setValue:@true forKey:@"checked"];