set alertview Yes button to bold and No button to normal

房东的猫 提交于 2019-12-05 01:37:19
Prince Agrawal

Your requirement is to "Highlight" Yes button.. In iOS 7 by default cancel button is the one which is highlighted. Unfortunately you can't simply change alertViewStyle here. But you do have a workaround.

Look at this answer.

Sk Borhan Uddin

You may use preferredAction default property of UIAlertController instead of UIAlertView.

UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"alert" message:@"My alert message" preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* yesButton = [UIAlertAction
                            actionWithTitle:@"OK"
                            style:UIAlertActionStyleDefault
                            handler:^(UIAlertAction * action)
                            {

                                [alertController dismissViewControllerAnimated:YES completion:nil];

                            }];

UIAlertAction* noButton = [UIAlertAction
                           actionWithTitle:@"Cancel"
                           style:UIAlertActionStyleDefault
                           handler:^(UIAlertAction * action)
                           {
                               [alertController dismissViewControllerAnimated:YES completion:nil];
                           }];

[alertController addAction:noButton];    
[alertController addAction:yesButton];
[alertController setPreferredAction:yesButton];

setPreferredAction will set your button title bold.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!