设置alertview是按钮加粗,没有按钮正常

Fah*_*kar 12 objective-c button uialertview ios

我有alertview,我有Yes和No选项.它看起来像下面.

在此输入图像描述

使用的代码是

UIAlertView *confAl = [[UIAlertView alloc] initWithTitle:@"" message:@"Are you sure?" delegate:self cancelButtonTitle:@"Yes" otherButtonTitles:@"No", nil];
confAl.tag = 888;
[confAl show];
Run Code Online (Sandbox Code Playgroud)

这是完美的但我希望是粗体而不是普通字体.

所以我切换了Yes和No按钮,如下所示.

在此输入图像描述

使用的代码是

UIAlertView *confAl = [[UIAlertView alloc] initWithTitle:@"" message:@"Are you sure?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
confAl.tag = 888;
[confAl show];
Run Code Online (Sandbox Code Playgroud)

有没有什么方法可以让Yes作为第一个按钮而No作为第二个按钮,Yes是否为粗体效果?

注意: 我想在iOS 6(相同的旧样式)和iOS 7(图像中的新样式)中也需要相同的效果.

Sk *_*din 23

您可以使用preferredAction默认属性UIAlertController而不是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];
Run Code Online (Sandbox Code Playgroud)

setPreferredAction 将您的按钮标题设置为粗体.


Pri*_*wal 5

您的要求是"突出显示"是按钮..在iOS 7中,默认情况下取消按钮是突出显示的按钮.不幸的是,你不能在这里简单地改变alertViewStyle.但你确实有一个解决方法.

看看这个答案.