【问题标题】:How to Change UIAlertController UIAlertAction Colour and add Checkmark Sign? [duplicate]如何更改 UIAlertController UIAlertAction 颜色并添加复选标记? [复制]
【发布时间】:2017-09-06 12:04:16
【问题描述】:

我想更改UIAlertController UIAlertAction TextColor 并在用户选择操作时显示复选标记图像。

我可以正常显示UIAlertController。但我怎样才能做到这一点?

任何人都可以建议我或帮助我这样做吗? 谢谢

【问题讨论】:

    标签: ios uialertcontroller uialertaction


    【解决方案1】:

    不可能/不建议覆盖UIAlertAction textcolor。您必须创建自己的视图并根据需要呈现它。有一些第三方库可以帮助您实现您想要的。

    【讨论】:

    • 不明白你的意思。
    • 不建议覆盖私有 API/属性,因为您的应用可能会被拒绝。请参阅 Apple 的文档。因此,不要修改 textcolor,而是创建自己的视图,其行为类似于 UIAlertController。您可以使用一些 3rd 方库来获得 UIAlertController 的外观。我希望你同意。
    【解决方案2】:

    试试这个 无需使用任何 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"];
    

    【讨论】:

      猜你喜欢
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-08
      相关资源
      最近更新 更多