UIActionsheet in the middle of the screen - iphone

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.

Related

UIActionsheet Ipad/Iphone

I'm currently using a UIActionsheet for my universal app, works great and all, but I want the iPad actionsheet to resemble the iPhone actionsheet.
Is there anything on the iPad that is similar to the iPhone actionsheet? Alternatively, is there a way to reposition the iPad actionsheet and popoverview WITHOUT a direction arrow?
Thanks
EDIT: Here is the code where I implement and add the actionsheet
adActionSheet = [[UIActionSheet alloc]initWithTitle:#"Title" delegate:self cancelButtonTitle:#"Cancel" destructiveButtonTitle:nil otherButtonTitles:#"Go to Site", #"Some other button", nil];
[adActionSheet showFromRect:CGRectMake(300, 1150, 200, 200) inView:self.view animated:YES];
On an iPad, action sheets are automatically shown in a popover. This can't be changed. You can't remove the array either. The UIActionSheet API doesn't support what you want.
Your only solution is a custom implementation that does what you want.
Actually you can remove arrow from UIPopover in ipad
[self.popoverController presentPopoverFromBarButtonItem:anItem
permittedArrowDirections:0
animated:YES];
or
[self.popoverViewController presentPopoverFromRect:rect
inView:self.view permittedArrowDirections:0 animated:YES];
The zero represent no direction.

How to make custom modal uiview like this?

I need some modal view on iPhone app where I will display few labels, one UIImageView and two buttons. Design needs to be whole custom.
Is this custom UIAlertView? How to make something similar?
There is a nice blog post by Jeff LaMarche about how to create a custom Alert View. You can take inspiration from there.
http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html
** UPDATE on April 24, 2017 **
Unfortunately the blog doesn't exist anymore. However you can retrieve the post from the Web Archive:
https://web.archive.org/web/20160430051146/http://iphonedevelopment.blogspot.com/2010/05/custom-alert-views.html
See the source for Tapku library. They have this option - you can always hack/tweak source code for it. Its not that difficult though, Just a lot of layer magic going around (e.g. the vignette effect). and most of the assets are images. You just need to break it down properly.
You can acquire that simply following the following steps
Create UIview (ViewA)of size 320*480 , so that it will cover whole screen of iPhone with background set to clearColor.This will serve as super view for our purpose;
Create another UIView (ViewB) of size 320*480 with background color set to black and opacity to 40%.
3.Now you can add any view on ViewB.
Now add ViewB to ViewA.
Finally you can Present this view where ever required. The effect will be, ViewA will cover the Background viewController, ViewB will server as suppressing effect for background view controller and views on B are the UIElement you will see.
Making a view like this is simple. You just need to create a custom view with the pieces that you want and just make it hidden or set the alpha to 0.0. Then un-hide it when you want to use it.
To prevent interaction with other items behind the view put a blank semi-transparent view right behind your custom view.
UIAlertView *alert = [[[UIAlertView alloc] initWithTitle:#"\n\Please wait. \n Authorising Credentials..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil] autorelease];
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 10, 40, 40)];
NSString *path = [[NSString alloc] initWithString:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:#"smile.png"]];
UIImage *bkgImg = [[UIImage alloc] initWithContentsOfFile:path];
[imageView setImage:bkgImg];
[bkgImg release];
[path release];
[alert addSubview:imageView];
[imageView release];
[alert addButtonWithTitle:#"Cancel"];
[alert show];

How do I get those small views from the bottom to appear in iOS SDK?

I'n talking about the small windows with buttons that come from the bottom when you need to confirm some action. For example, if you want to delete a photo from an album and press the trash icon, a small view jumps from the bottom and asks if you want to delete the photo or cancel
How do I get those views to appear?
Use a UIActionSheet.
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:#"Some Action"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:#"OK"
otherButtonTitles: nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheet showInView:self.view];
[actionSheet release];
You'll want to look at the UIActionSheet object: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIActionSheet_Class/Reference/Reference.html
An example here: http://ykyuen.wordpress.com/2010/04/14/iphone-uiactionsheet-example/

very weird error of uiactionsheet clicks not working on the bottom of the actionsheet

i have a uiactionsheet and the buttom button doesnt work correctly the first time i press it, or the second, but only numerous times after trying. I tried removing the cancel button at the bottom and leaving a button title however none of these steps solved the problem.
This is the code i am using:
UIActionSheet *aSheet = [[UIActionSheet alloc]
initWithTitle:nil
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle: #"Close"
otherButtonTitles:#"6940313388", #"2", #"3", #"4", nil];
I've found that if you present the action sheet from the wrong view, whatever bottom bar may exist in your view will block the user interaction of the action sheet but not visually obscure it.
Experiment with calling showFromToolbar:, showFromTabBar: and showInView: to see which works properly (I can't remember at the moment).
I use...
[aSheet showInView:appDelegate.window]

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

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];