How to Change UIAlertController UIAlertAction Colour and add Checkmark Sign?

910 views Asked by At

I want to Change UIAlertController UIAlertAction TextColor and display Checkmark image when user Select an action.

i am able to show normal UIAlertController. but how can i achieve this?

Can any one please suggest me or help me to do that? Thanks

2

There are 2 answers

0
Kuldeep On BEST ANSWER

Try this There's no need to use any 3rdParty Library

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];

And If you want to set Any button with CheckMark by default than add this.

[yesAction setValue:@true forKey:@"checked"];
2
Maulik Bhuptani On

It is not possible/advisable to override UIAlertAction textcolor. You will have to create your own view and present it as per your needs.There are some 3rd party libraries which can help you achieve what you want.