Display UIActionSheet in iphone the same as ipad - ios

I have a a UIButton, and I would like to add a UIActionSheet.
How can I make the iphone version look like so:
If there is a way of doing it another way, meaning not with UIActionSheet, I'm open to hear other ways.
Hope I was clear enough. If you have questions, please feel free to ask.

You can do this in a native way in iOS8 only with the following
UIPopoverPresentationController *popOverController = [[UIPopoverPresentationController alloc] init];
popOverController.popoverContentSize = CGSizeMake(150, 160);
[popOverController setDelegate:self];
popOverController.sourceView = self.view;
popOverController.sourceRect = sender.frame;
popOverController.permittedArrowDirections = UIPopoverArrowDirectionUp;
[self presentViewController:popOverController
animated:YES
completion:nil];
you can use one of custom controls from cocoacontrols for iOS7 support
Good luck

Related

Popover crashing on iPad (SpriteKit game)

Recently I discovered that it’s necessary to use Popover to display the ActivityViewController on iPad. I found this website as a main reference:
http://pinkstone.co.uk/how-to-share-things-with-a-uiactivityviewcontroller/
It’s perfectly explained, but I can’t make it work from my SpriteKit game. I double-checked with other examples and all seems to be in its place... but this crash on iPad anyways, without any meaningful message (on iPhone it works). I have no idea on what’s wrong. If somebody experienced the same, any clue will be very welcome!
UIActivityViewController *activityController = [[UIActivityViewController alloc]initWithActivityItems:#[twitterText] applicationActivities:nil];
UIViewController* viewController = self.view.window.rootViewController;
activityController.modalPresentationStyle = UIModalPresentationPopover;
[viewController presentViewController:activityController animated:YES completion:nil];
UIPopoverPresentationController *popController = [activityController popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionDown;
popController.sourceRect = CGRectMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame),200,200);
The solution was adding
popController.sourceView = self.view;
before the sourceRect. Thanks and kudos to Warren Burton.

UIPopoverController alternative on iphone devices

I have been searching for almost 2 hours on how to implement UIPopoverController in swift language, at the end, i found out that this api are exclusive for iPad devices only.
How will i be able to make a drop down list on iPhone devices?
please someone help me, at lease with the name of the api so that i know what to search for
You can you third party libraries for that:
FPPopover
WEPopover
or if you don't need iOS 7 support you can use iOS 8 new API which answered in this question
UIPopoverPresentationController on iOS 8 iPhone
i depends on your needs. You can show UIPickerView, present an action sheet or segue to another VC and then go back - these are standard ways.
#property(nonatomic,retain) UIPopoverPresentationController *popoverPresentationController;
- (IBAction)showPopover:(id)sender {
UIViewController *popoverViewController = [[UIViewController alloc] initWithNibName:#"NameViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:popoverViewController];
popoverViewController.preferredContentSize = CGSizeMake(280, 200);
navigationController.modalPresentationStyle = UIModalPresentationPopover;
_popoverPresentationController = navigationController.popoverPresentationController;
_popoverPresentationController.delegate = self;
_popoverPresentationController.sourceView = self.view;
_popoverPresentationController.sourceRect = [sender frame];
navigationController.modalPresentationStyle = UIModalPresentationPopover;
navigationController.navigationBarHidden = YES;
[_viewController presentViewController:navigationController animated:YES completion:nil];
}

Custom UIView like UIPopoverController

Would like to learn how UIPopoverController style UIViews are created.Below is the image from Storehouse iOS app running on iPhone(apple design award winner) , you can see the view moreover looks like UIPopoverController ,any help is greatly appreciated.
You can handle your own custom view check out this How to Place custom view in IOS over another view
You can use this
- (IBAction)ContinueToPayment:(id)sender {
PayByVC *Newpage = [[PayByVC alloc] initWithNibName:#"PayByVC" bundle:nil];
Newpage.checkOutInfoDict=checkOutDict;
Newpage.modalPresentationStyle = UIModalPresentationOverCurrentContext;
Newpage.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
Newpage.view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:.4];
Newpage.delegate = self;
[self presentViewController:Newpage animated:YES completion:nil];
}

Apple's controllers not presenting properly in iOS7

In my iOS app i present standerd controllers MFMessageComposeViewController and UIImagePickerController.
But they both presenting with strange navigation bar.
How can i fix this problem?
UPD code for presenting controllers
UIImagePickerController:
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = sourceType;
cameraUI.allowsEditing = YES;
cameraUI.delegate = self;
[self presentViewController:cameraUI animated:YES completion:nil];
MFMessageComposeViewController:
MFMessageComposeViewController *messageViewController = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]) {
messageViewController.view.backgroundColor = [UIColor whiteColor];
messageViewController.messageComposeDelegate = self;
recipient= [NSStringMask maskString:recipient withPattern:#"\\+(\\d{1}) \\((\\d{3})\\) (\\d{3})-(\\d{2})-(\\d{2})"];
messageViewController.recipients = #[recipient];
messageViewController.body = body;
[self presentViewController:messageViewController animated:YES completion:nil];
}
In iOS 7, the status bar and the navigation is translucent by default. To make the view act 'normal' like in iOS 6. you need to add this to the controller you are presenting.
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
self.edgesForExtendedLayout = UIRectEdgeNone;
If you want to read up more about changes in views. Check out this post. I find it a nice quick overview whats changed.
http://www.brianjcoleman.com/ios7-weve-got-a-problem/
See this question. I used the second answer, though I suspect the first would work for me also.

Changing size of modal dialog ios

How to I change the size of modal dialog? Why is this not working?
SlingDialogViewController *slingDialog = [[SlingDialogViewController alloc] init];
slingDialog.modalPresentationStyle = UIModalPresentationFormSheet;
slingDialog.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
slingDialog.view.superview.frame = CGRectMake(0, 0, 900, 700);
[self presentModalViewController:slingDialog animated:YES];
Do this:
SlingDialogViewController *slingDialog = [[SlingDialogViewController alloc] init];
slingDialog.modalPresentationStyle = UIModalPresentationFormSheet;
slingDialog.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:navController animated:YES completion:nil];
slingDialog.view.superview.frame = CGRectMake(0, 0, 900, 700);
slingDialog.view.superview.center = self.view.center;
It's important to call presentViewController:animated:completion first, from my experience at least.
The modal controllers in iOS have fixed sizes. I don't recommend trying to change them, it never works reliably.
A workaround is to implement it by yourself. A modal (presented) controller is a very simple functionality:
A view overlapping your presenting controller, so that it can't be clicked (and it is dimming the contents to make them look backgroundish)
A child view controller (and its view) added to your controller.

Resources