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

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

在此处输入图像描述

使用的代码是

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

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

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

在此处输入图像描述

使用的代码是

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

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

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

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

看看这个答案 。

您可以使用UIAlertController preferredAction默认属性而不是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将按钮标题设置为粗体。