UIActionSheet to Display Text Only Messages

UIActionSheet offers a really handy basic menu system, where each button presents an option for the user to choose from. For example, the figure below shows how I am using UIActionSheet to show three menu options for a shopping list view I am working on.

I’ve found another good use for UIActionSheet, to show text messages with minimal coding and overhead. You might use this idea to show content sensitive help text, or maybe display a message that is shown only once upon the first run of an application.

You can get an idea of the look that I’m after from the figure below. In this example I’m showing nothing more than three paragraphs of text and a button to dismiss the view.

It’s almost embarrassing to show the code as there’s really nothing to it:

    UIActionSheet *msg = [[[UIActionSheet alloc] 
        initWithTitle:@"Lorem ipsum dolor...text goes here" 
        cancelButtonTitle:nil  destructiveButtonTitle:nil 
        otherButtonTitles:@"Okay", nil] 
    [msg showInView:window];

We have no need for a delegate in this case, and by setting all but the “Okay” button to nil, we have just one button.

The beauty of using a UIActionSheet for this type of information is that presentation is handled for you (sliding into place), all other UI elements are obscured (a modal presentation) and it’s ridiculously simple to implement.

  1. Thanks for the tip! If you use the destructiveButtonTitle for your “Clear Shopping List” button, it will be red, making it clear that it has a non-reversible, and destructive action. It also makes it easier for your users to differentiate and visually find the two sort options.

    For my app “Love Bottle” I wanted to display a picture at the top of the action sheet, instead of a label. In order to do this, I had to make a text label big enough to create space for the image, and then add a subview:

    pic.frame = CGRectMake(self.view.center.x-50.0, 10.0, 100.0,100.0);
    [actionsheet addSubview:pic ];

    The periods in the title are visible until they are covered up with the picture. Without them, the multiple returns are ignored, adding only one additional line of space.


  2. Great idea! I might use this for a ‘legal confirmation.’ Not the big EULA, but something like — ‘i’m going to be posting your location … [Accept] [Don’t Accept]’

  3. Nice article, I was looking for this kind of option for 2 days, I was implementing a UIView in a UIView … omg this option is WAY easier.


  4. Is it possible, to place multiple textfields and labels in uiactionsheet?

    • Chances are you will need to code the bulk for the effect you are after – for example, creating a UIView that holds labels and textfields and slide it up from the bottom.

Comments are closed.