Change the color of a button on a standard pop-up action - iphone

I am using a standard pop up action in my iphone app (the pop up at the bottom of the screen). This has 2 buttons "ok" and "cancel". It seems the standard colour scheme is to have the top button red. I want to change this so the top button is green. I have been googling forever and can't find the solution. Any ideas would be great. Thanks

You can browse through ActionSheet ( I assume you use UIActionSheet class) subviews - like that:
NSArray* subViews = [aSheet subviews];
for (UIView* sView in subViews)
{
...
}
And change subviews properties there as you like.
You can also create UIActionSheet without any buttons at all:
UIActionSheet* aSheet = [[UIActionSheet alloc] initWithTitle:#"\n\n\n" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
And afterward create your own custom buttons and add them to the ActionSheet view. (put more \n to the title to enlarge Sheet height)

I assume you're referring to a UIActionSheet. In a UIActionSheet, you can define a button that cancels the action and has a black background, a button that marks a destructive action and has a red background, and all other buttons which have white backgrounds. Which option corresponds to which class of actions can be specified in the initialization of the UIActionSheet using – initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:.
The design of a UIActionSheet, including why you should only use these colors for your buttons, is explained in the iPhone Human Interface Guidelines. I'd follow Apple's suggestions in this regard, as they will make your application easier to use.

UIActionSheet *action = [[UIActionSheet alloc] initWithTitle:#""
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil,#"Mail",#"Facebook",#"Twitter",nil
otherButtonTitles:nil];
NSArray *buttons = [action subviews];

Related

Highlight Top Button in UIAlertView

I've got a UIAlertView with 3 buttons displayed vertically by default in the UIAlertView. I'd like the top button to be bold/highlighted. From my understanding and testing, the 'cancel' button is the one that is highlighted. The problem is no matter how I set the cancel button, it is placed last in this row. I cannot get it to be the first button.
I've tried setting the cancel button explicitly
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:#"Top Button"
otherButtonTitles:#"Middle Button", #"Bottom Button", nil];
as well as setting the index of the cancel button
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"Top Button", #"Middle Button", #"Bottom Button", nil];
alert.cancelButtonIndex = 0;
This problem is actually caused by changes Apple made in iOS 7. Prior to iOS 7 we were able to access the subviews of an UIAlertView by calling [alertView subviews]. But since iOS 7 doesn't give us access to any subviews ([alertView subviews].count will always return zero) we can't customize UIAlertViews the way we used to.
So the only way to achive your goal under iOS 7 is to build a custom view that looks like UIAlertView and then customize it as you like.
But if you're coding for an iOS version prior to iOS 7 than you could use this easy hack to access a button:
UIAlertView *alertView = [[UIAlertView alloc] init];
[alertView addButtonWithTitle:#"Yes"];
UIButton *yesButton = [alertView.subviews lastObject]; //is nil under iOS 7
This way you would get access to the first button. After that you can customize your UIAlertView as usual.
By the way: Apple did not only want to give all UIAlertViews the same design by changing the way we can customize them. The reason lies in HCI researches (Human-Computer-Interaction). People tend to think the bottom button is always the 'default' answer if that is the way it is implemented throughout all apps.
Also the bottom button is the only highlighted button in a UIAlertView. So its visual weight is stronger than the visual weight of the button with about the same amount of text. That's another factor why people tend to choose this one. And that is also the reason why the highlighted button never should cause disastrous and irreversible actions ('You wanna delete all your saved games' should always highlight the button 'Keep my saved games' and not the one telling 'Delete everything').
Therefore Apple always makes the Cancel Button the bottom one no matter in which order you added the buttons. So if your app doesn't make use of a fully custom interface and uses many User Interface Elements provided by Apple than I highly recommend you to not try to change that behavior and make the bottom button your 'default' button.
There is a customer alert view DTAlertView.
I hope it can help you.

How to set identical appeareance to buttons for an UIAlertView?

By default, a UIAlertView with two buttons has different alpha for each button.
Is there a way to make them look identical with different text, without subclassing UIAlertView, or making a custom alert view?
Here is what i used:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
kAlertTitleOrderType message:kAlertMessageOrderType delegate:delegate
cancelButtonTitle:nil otherButtonTitles:#"Collection", #"Delivery", nil];
If you set the cancel button to nil when calling initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles: then no cancel button will be added (this is the one that looks different). You can then add other buttons as you require.

How to customize a UIAlert View Popup

I was wondering how to create and customize a UIAlert View Popup, like ones in popular games such as Angry Birds or Cut the Rope.
I just want to say can you please rate my game and have 3 options to choose from. I want to design it so the text font and color changes and the background color can change to a picture or something? Thanks in Advance! :)
If your UIAlert is short enough to fit without the inherent scroll bar of longer text, then this will work:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Title Here" message:#Message here..." delegate:self cancelButtonTitle:#"Okay" otherButtonTitles:nil];
((UILabel*)[[alert subviews] objectAtIndex:1]).textAlignment = UITextAlignmentLeft;
((UILabel*)[[alert subviews] objectAtIndex:1]).font = [UIFont systemFontOfSize:12];
[alert show];
You should try subclassing UIAlertView using this tutorial. Such UIAlertViews can be achieved with either a subclass of UIAlertView or by creating a separate view all together that simulates the look and feel of a UIAlertView.

UIAlertView with 3 buttons > spacing on third button

I am creating a simple alert view with 3 buttons, each button has equal importance, there is no cancel button or anything like that:
UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:#"msg" delegate:self cancelButtonTitle:nil otherButtonTitles:#"button1",#"button2",#"button3",nil];
[alert show];
The third button has extra space above it, as if it was a cancel button.
I would like the space to be identical in between buttons.
Any idea?
Unfortunately, there is no easy way to do so (you'd have to literally reinvent the wheel, subclassing UIAlertView not necessarily being a very viable option).
However, you might be interested by the BlockAlertsAnd-ActionSheets library, that would give you nice, block based, alert views that do offer a consistent spacing between buttons.

UIActionsheet in the middle of the screen

I want to show a UIActionSheet in the middle of the screen.I tried with the following code
UIView *placeholderview=[[UIView alloc]initWithFrame:CGRectMake(0, 310, 320, 100)];
[self.view addSubview:placeholderview];
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Open File",#"Save FIle",#"New File",#"Export Image",nil];
[actionSheet showFromRect:CGRectMake(0,0, 320, 10) inView:placeholderview animated:YES];
[actionSheet release];
I get the result as desired but i can click only cancel button, and the half of export image button.I don't know where i am going wrong.Kindly please any body help me.What should i do to make it working.
UIActionSheet is designed to be presented from the bottom of the screen.
It provides methods for presenting from a toolbar or tab bar in cases where those UI elements may cause obstruction.
Why are you wanting to show the action sheet in the middle of the screen. I wouldn't recommend this because it looks wrong, and isn't the designed behaviour of the control.
The method you are currently using is for iPad - it shouldn't be used on iPhone, as it causes undefined behaviour (as you are experiencing).
UIActionSheet's showFromRect:inView:animated: method is only supposed to be used on iPad. Its behavior on iPhone is undefined.