Customizing UIAlertView - iphone

Anyone have code to make this:
(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).

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.

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 :-)

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.

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

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.

Related

How to add more than eight buttons in a UIAlertView?

I want to add more than 8 buttons in UIAlertView but when I am adding buttons, they are covering each other and not scrolling. The title is also hiding.
How can I resolve this and add some scrolling in the alertview ??
Seems like this kind of question comes up at least once a day on StackOverflow, but if you want to mess around with the various components within a UIAlertView, the short answer is: DON'T.
If you look at Apple's documentation for UIAlertView, within the first screenful of text it states:
Subclassing Notes
The UIAlertView class is intended to be used as-is and does not
support subclassing. The view hierarchy for this class is private and
must not be modified.
This means that there's a decent chance that any mucking around within UIAlertView hierarchy could catastrophically break your app in future iOS release.
So if you want to add scroll bars or bells & whistles, you really should create your own custom UIView (which looks like a UIAlertView, but is wholly of your own creation)
If you have more buttons then UIActionSheet is the best option than using UIAlertView. If you dont want to use UIActionSheet there is always a custom View to your rescue!
You should really rethink your UI if you need more that 8 button in a UIAlertView. 8 button is the maximum the standard alert view can handle.
Either build your own alert view or use a normal view controller with a table view.
Not sure if it's necessary but as an alternative, you can present another ViewController/ModalVC that will have all the attributes that you may require....
Just move ahead with CustomView, Otherwise not possible with UIAlertView to meet up with your requirement :
Reference links :
http://iphonedevelopment.blogspot.in/2010/05/custom-alert-views.html
http://iosdevtricks.blogspot.in/2013/04/creating-custom-alert-view-for-iphone.html
https://stackoverflow.com/a/6965828/434898
If you want to add many buttons you can use a custom implementation for the alertView.
A nice example is FUIAlertView
Or you could use WEpopover and add to it a table view.

Change UIAlertView button layout

I want to show two buttons in 'UIAlertview'. Because the button text is very long, I want the buttons to appear one above the other in a vertical stack instead of side by side. Is it possible to do this?
You would need to subclass UIAlertView and create your own custom alert with the buttons as you described.
Unfortunately your only choices are to either make the button text shorter or to add another button. UIAlertView only lays out rows of buttons when there are more than two.
Aside from that, you can subclass UIAlertView, but it would probably be easier to simply create your own custom view / view controller at that point.

how to set UIView Background color with glass effect similar to UIAlertView

i need to place one textfield with 3 buttons in an alertview. According to UIGuidelines it is not possible,so Instead of AlertView I place UIView similar to Alertview.
And i animate it like Alert view using this code.
If works fine.
it displays with white Color Background,But i need to design same as AlertView Background color and style like round edged.
How can i done this.
can anyone pls help me.
Thank u in advance.
The UIAlertView background is simply an image. You are better off creating a custom png image and using it as your background.
That can be done with CoreGraphics / Quartz functions, but it is quite complicate to simulate the same effect
Another approach would be to create a UIImageView with a streched uiimage you mock in Photoshop or so.
;)
EDIT: You can set a custom view directly into UIAlertView like this:
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[_addPersonAlert setValue:auxContainerView forKey:#"accessoryView"];
}else{
[_addPersonAlert addSubview:auxContainerView];
}
There are a lot of open source, subclasses of UIAlertView that might accomplish what you want to do. I'll leave a couple as an example but you can certainly google out some other options as well.
https://github.com/rtecson/RTAlertView
https://github.com/lmcd/LMAlertView
In my case I used once, LMAlertView which let's you access it's "contentView" property, to set any UIView that you want as part of the alert. Have in mind that you can add a hierarchy of views into a single UIView and set this container view as the contentView of the alert.

Dismissing a UIAlertView on any touch

I am trying to use a UIAlertView essentially as a label (no title or buttons, just display text) for aesthetic purposes. I want to be able to continue to use everything else in the app (touch other buttons, etc.) while the alert view is being shown. Unfortunately, I cannot seem to invoke touchesBegan or a selector using a UITapGestureRecognizer while the alert view is shown. These both work when the alert view is not shown, but it seems like the alert view disables detection of any touches (other than touching its own buttons if it had them).
Does anyone know a way I could work around this? Even if I was to create a UILabel and set its background to the alert view image that would work.
Thanks for your help.
The alert view puts a new window on top of the entire screen which intercepts touches. It's expressly designed to prevent you from doing what you're trying to do. Why are you trying to abuse alerts in this manner anyway? It's generally a bad idea to take existing UI and use them in non-standard ways, as well as a possible reason to get rejected.
Your best bet is to just draw the "alert view" yourself, either in code or as a pre-baked image. Unfortunately this means you cannot leverage the built-in code that draws UIAlertView, but it's probably best that you don't try to appear identical to a UIAlertView anyway.

how to add a png to UIAlert button for iphone

is it possible to change
1)rectable box to circular
2)add a png to alert box
3)any custom UI
A UIAlertView is a UIView just like anything else. You can add whatever you want to it.
I would try setting up a UIAlertView with some blank lines for the message (to give you space to place your own elements) and adding elements the way you would anywhere else:
[alertView addSubview:myAwesomeButton];