Set alertview Yes button for bold and No for normal operation

I have an alertview where I have the Yes and No options. He looks lower.

enter image description here

Code used

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

This is perfect, but I want Yes to be a bold font, not like a regular font.

So, I turned on the Yes and No buttons, as shown below.

enter image description here

Code used

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

Is there a way that we can have Yes as the first button, and No as the second button with Yes as a bold effect?

Note: I want to use the same effects in iOS 6 (the same old style) and iOS 7 (new style, as indicated above in the image).

+8
ios objective-c button uialertview
source share
2 answers

Your requirement is the Highlight Yes button. In iOS 7, the button that is highlighted is canceled by default. Unfortunately, here you cannot just change alertViewStyle. But you have a workaround.

Check out this answer .

+4
source share

You can use the 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 set the name of your button in bold.

+13
source share

All Articles