Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7760015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:46:20+00:00 2026-06-01T13:46:20+00:00

I am trying to create a UIAlertView with three buttons (which will be stacked).

  • 0

I am trying to create a UIAlertView with three buttons (which will be stacked). I would like the Cancel button to be in the middle, between the two other buttons. I have tried setting the cancelButtonIndex to 1, but if there are two other buttons, it simply places them at indexes 0 and 1. I know I could just change the names of the buttons, but I want the darker blue formatting of the cancel button.

EDIT: **
Please note – I know how to get the three buttons with the titles in the correct order, but only if all three buttons essentially look like ‘other’ buttons; I want the cancel button to have the cancel button dark blue background so that it will look like a regular cancel button.
**

I’ve tried

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:button1Title,button2Title,nil] autorelease];
alert.cancelButtonIndex = 1;
[alert show];

and

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil] autorelease];
alert.cancelButtonIndex = 1;
[alert addButtonWithTitle:button1Title];
[alert addButtonWithTitle:button2Title];
[alert show];

and

UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:addButtonWithTitle:button1Title,nil] autorelease];
alert.cancelButtonIndex = 1;
[alert addButtonWithTitle:button2Title];
[alert show];

to no avail. Is it even possible to accomplish what I am trying to do?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:46:22+00:00Added an answer on June 1, 2026 at 1:46 pm

    I have two ancillary points to this answer.

    1) While, to the best of my knowledge, Apple has not rejected an app for reasonable modification of a UIAlertView; They have said that the view hierarchy of classes like UIAlertView should be considered private.

    2) This question is a good example of why you should ask a question more about your end goal rather than the steps to get there. The only reason I know what this question is about is as a result of a comment left at my answer here.

    Answer:

    Because of your comment I know that you are looking to create a UIAlertView that has stacked buttons even when there are only 2 buttons.

    I find the most logical place for code like this is in a category. Since generally the code needed to manipulate the alert-view needs to be around the show call, I created a category method I call instead of show and the method in turn calls show itself.

    -(void)showWithButtonsStacked{
        static NSString *tempButtonTitle = @"SomeUnlikelyToBeUsedTitle";
        BOOL willAddFakeButton = (self.numberOfButtons == 2); // Button are only side by side when there's 2
        if (willAddFakeButton){
            self.clipsToBounds = YES;
            [self addButtonWithTitle:tempButtonTitle]; // add temp button so the alertview will stack
        }
        BOOL hasCancelButton = (self.cancelButtonIndex != -1); // If there is a cancel button we don't want to cut it off
        [self show];
        if (willAddFakeButton){
            UIButton *cancelButton = nil;
            UIButton *tempButton = nil;
            for (UIButton *button in self.subviews) {
                if ([button isKindOfClass:[UIButton class]]){
                    if (hasCancelButton && [button.titleLabel.text isEqualToString:[self buttonTitleAtIndex:self.cancelButtonIndex]]){
                        cancelButton = button;
                    } else if ([button.titleLabel.text isEqualToString:tempButtonTitle]) {
                        tempButton = button;
                    }
                }
            }
            if (hasCancelButton){ // move in cancel button
                cancelButton.frame = tempButton.frame;
            }
            [tempButton removeFromSuperview];
    
            // Find lowest button still visable.
            CGRect lowestButtonFrame = CGRectZero;
            for (UIButton *button in self.subviews) {
                if ([button isKindOfClass:[UIButton class]]){
                    if (button.frame.origin.y > lowestButtonFrame.origin.y){
                        lowestButtonFrame = button.frame;
                    }
                }
            }
    
            // determine new height of the alert view based on the lowest button frame
            CGFloat newHeight = CGRectGetMaxY(lowestButtonFrame) + (lowestButtonFrame.origin.x * 1.5);
            self.bounds = CGRectMake(0, 0, self.bounds.size.width, newHeight);        
        }
    }
    

    The way this method accomplishes it’s goal is to add a temporary button to the alert-view to force the alert-view to stack the buttons, then it removes the temporary button and adjusts the height. Since it’s a category method you use it simply by calling:

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test title" message:@"message" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
    [alert showWithButtonsStacked];
    

    This code results in an alert like this:

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying create a search box which will search datatables. The search box
I am trying to create a UIAlertView that has 3 options and no cancel
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Trying to create my first iPhone app that would play back audio. When I
Possible Duplicate: UIAlertView not showing message text I am trying to create a simple
I'm trying create a query that will output a total number, as well as
I am trying create a data.frame from which to create a graph. I have
I'm currently trying create a service that will return results of a OLAP cube
I am trying create system in which I can login from php and then
I'm trying create a simple audio stream server like a concept proof, but I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.