9

Anyone have code to make this:

UIAlertViewHack
(source: booleanmagic.com)

or better yet, a 3x2 grid of buttons with images using the UIAlertView object?

I don't care about the textfield, it's the buttons in a grid I want (preferably with images rather than text).

Glorfindel
  • 21,988
  • 13
  • 81
  • 109

5 Answers5

27

I think your best bet is to forget customizing UIAlert view and build a custom view yourself.

For one, what you're showing really isn't an "alert" so it's counter to what UIAlertView is designed to be for. This means that you're changing the UI paradigm on the user which is never a good idea.

Second, it would be much easier to animate a custom view into place than to try and hack UIAlertView to get it to do what you want.

August
  • 12,139
  • 3
  • 29
  • 30
11

First you need to make the alert box bigger to accomodate your controls, yet it has to be placed at the center.

For this, instead of setting the frame size, your the message text with "\n"s as necc. e.g.:

alert = [[UIAlertView alloc] initWithTitle:@"Rate this picture."
message:@"Tap a star to rate.\n\n\n\n " /*------ look at here!!----*/
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];

Then use a UIAlertViewDelegate for the alertview.

override its, viewWillAppear: add your buttons and set their frames manually at desired position.

OR: create a entire view with a view controller, and add the view to the alert box like:

[myalertview addSubvew:mycomplexalert];

Hope this will come into your help :)

I am using alert boxes for rating input with star images,twitter,fb feedback etc.

UPDATE iOS7:

For iOS 7, create your own view with components and set it as the alertview's accessory view:

[alert setValue:imageView forKey:@"accessoryView"]; 

Its thats simple :-)

  • 1
    The "\n\n\n\n" hack does not seem to work with the current iOS 7 Beta 1 release! I'm not sure if this will be changed in the final iOS 7.. – Raphael Jun 11 '13 at 08:53
  • For iOS 7, create your own view and set it as the alertview's accessory view: [alert setValue:imageView forKey:@"accessoryView"]; – Shaikh Sonny Aman Jul 14 '14 at 10:47
  • I think there might be a reason why "accesoryView" is not publicly accessible. So this might break in future versions or might be rejected by Apple. – Raphael Jul 15 '14 at 12:34
  • Right, probably its still not stable but they demonstrated on WWDC 2013(forgot which video), so probably they won't reject. On iOS8 beta, it doesn't work - even in system alerts with accessory view :/ – Shaikh Sonny Aman Jul 16 '14 at 10:38
6

I wrote a almost pixel perfect UIAlertView replacement, that's also fully configurable. Have a look at CODialog if it fits your needs.

  • that's great @Erik Aigner.. however I just got an old (iOS6) project that uses your library and we need to migrate it to iOS7.. your library uses the look/feel of iOS6.. any idea how I can upgrade it to look/feel like iOS 7? – abbood May 09 '14 at 08:25
  • @abbood just override the drawing methods –  May 09 '14 at 08:48
  • @ugh man that's a lot of lines of code.. do you know if apple would accept an app that has your library considering that they will only accept code that was compiled against iOS 7? – abbood May 09 '14 at 09:15
6

This tutorial covers how to subclass UIAlertView to achieve an input text box. It explains how to enlargen the view, add subviews (like text boxes or images) and make a transform to move the box up higher on the screen.

Hauke
  • 2,554
  • 4
  • 26
  • 29
  • This does NOT go over how to change the size of the view, but it is helpful in showing how to add the textbox and use the stuff entered into it. – sasquatch Nov 10 '11 at 19:18
4

There are no in-built components for this. UIAlertView should just have text and buttons as per the HIG document.

You will have to create your own view and add controls to it. The HeadsUpUI example in the SDK shows how to show a custom menu-like view as an overlay.

Hope that helps.

lostInTransit
  • 70,519
  • 61
  • 198
  • 274