iPhone Developer Tips Stats: Past 30 days - Pageviews: 88,766 Visitors: 61,679 Thank you everyone! Let's shoot for 100,000 by May. Pass it on...
|
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"
delegate:nil
cancelButtonTitle:nil destructiveButtonTitle:nil
otherButtonTitles:@"Okay", nil]
autorelease];
[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.
Comments
2 Responses to “UIActionSheet to Display Text Only Messages”
Leave Comment
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:
initWithTitle:@”.\r.\r.\r.\r.\r”
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.
-Seth
Great stuff Seth, thanks!
John