UIPopoverPresentationController can't setup arrow color - ios

I am trying to present popover with UIPopoverPresentationController class on the iPhone.
I need to present navigation controller inside the popover. So I do the following:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
viewController.preferredContentSize = size;
navigationController.modalPresentationStyle = UIModalPresentationPopover;
self.currentPopoverController = navigationController.popoverPresentationController;
self.currentPopoverController.backgroundColor = [UIColor commonApplicationBgColor];//My common app blue color
self.view.alpha = 0.7;
[self presentViewController:navigationController animated:YES completion:nil];
It is working, but arrow colour is differ from the popover navigation bar background colour. I checked they use the same [UIColor commonApplicationBgColor], but it looks like arrow colour is darker. Tried setup alpha for self.currentPopoverController.backgroundColor, but it is still has wrong color.
Please check image:

if you don't want arrow then you can pass 0 to permittedarrowdirection like,
[popoverController presentPopoverFromRect:YOUR_RECT
inView:self.view
permittedArrowDirections:0
animated:YES];
Update :
you can set like,
popover = [[UIPopoverController alloc] initWithContentViewController:contentViewController];
popover.backgroundColor = contentViewController.view.backgroundColor;
set bacground color to popovercontroller.
Update 2 :
myPopoverViewController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:myPopoverViewController animated: YES completion: nil];
// Get the popover presentation controller and configure it.
UIPopoverPresentationController *presentationController =
[myPopoverViewController popoverPresentationController];
presentationController.permittedArrowDirections =
UIPopoverArrowDirectionLeft | UIPopoverArrowDirectionRight;
presentationController.sourceView = myView;
presentationController.sourceRect = sourceRect;
presentationController.backgroundColor = [UIColor grayColor]; //set your expacted color here.
Hope this will help

Related

Different navigation bar behaviour between CABTMIDILocalPeripheralViewController and CABTMIDICentralViewController

I am struggling to understand why the following views, one for CABTMIDILocalPeripheralViewController and the other for CABTMIDICentralViewController show different behaviour in my iOS app (written in Objective-C)
- (IBAction)configureCentral:(id)sender
{
CABTMIDICentralViewController *viewController = [CABTMIDICentralViewController new];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController]; // this will present a view controller as a popover in iPad and modal VC on iPhone
viewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:#selector(doneAction:)];
navController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popC = navController.popoverPresentationController;
popC.permittedArrowDirections = UIPopoverArrowDirectionAny;
popC.sourceRect = [sender frame];
viewController.preferredContentSize = CGSizeMake(320., 400.);
popC.backgroundColor = [UIColor darkGrayColor];
viewController.view.backgroundColor = [UIColor darkGrayColor];
UIButton *button = (UIButton *)sender;
popC.sourceView = button.superview;
[self presentViewController:navController animated:NO completion:nil];
}
Opens a popup view on an iOS device, which does not show any 'done' button to dismiss the view.
CABTMIDICentralViewController shows no button to close/dismiss the view
While on an iPad tapping outside the view will close it, on an iPhone the view takes the size of the screen and exiting/closing becomes impossible.
The same code used for the CABTMIDILocalPeripheralViewController works as expected.
- (IBAction)configureLocalPeripheral:(id)sender
{
CABTMIDILocalPeripheralViewController *vController = [[CABTMIDILocalPeripheralViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:vController];
vController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:#selector(doneWithPeripheral:)];
navController.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController *popC = navController.popoverPresentationController;
popC.permittedArrowDirections = UIPopoverArrowDirectionAny;
popC.sourceRect = [sender frame];
vController.preferredContentSize = CGSizeMake(320., 400.);
popC.backgroundColor = [UIColor grayColor];
vController.view.backgroundColor = [UIColor darkGrayColor];
UIButton *button = (UIButton *)sender;
popC.sourceView = button.superview;
[self presentViewController:navController animated:NO completion:nil];
}
CABTMIDILocalPeripheralViewController has a 'done' button
What is going wrong here? I have tested to make the views wider to see whether available space in the Navigation bar would have caused this.
Thanks.

UIPopoverPresentationController width and height not setting

I am trying to present a popover controller but for some reason I can't get the width/height of the popover to set correctly. Here's the code I am using:
Here's my code:
UIStoryboard* myStoryboard = self.storyboard;
ScenarioPopOver* popOver = (ScenarioPopOver*)[myStoryboard instantiateViewControllerWithIdentifier:#"scenarioPopover"];
popOver.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:popOver animated:YES completion:nil];
// configure the Popover presentation controller
UIPopoverPresentationController *popController = [popOver popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionUp;
popController.delegate = self;
// in case we don't have a bar button as reference
popController.sourceView = self.view;
popController.sourceRect = CGRectMake(self.view.center.x - 25.0, 10.0, 50.0, 50.0);
But the popover keep coming out like this:
Just in case someone stumbles across this issue. I was trying to set the preferredContentSize on the UIPopoverPresentationController and not the UIViewController within it. Correct code is below:
UIStoryboard* myStoryboard = self.storyboard;
ScenarioPopOver* popOver = (ScenarioPopOver*)[myStoryboard instantiateViewControllerWithIdentifier:#"scenarioPopover"];
popOver.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:popOver animated:YES completion:nil];
// configure the Popover presentation controller
UIPopoverPresentationController *popController = [popOver popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionUp;
popController.delegate = self;
popOver.preferredContentSize = CGSizeMake(400.0, 300.0);
// in case we don't have a bar button as reference
popController.sourceView = self.view;
popController.sourceRect = CGRectMake(self.view.center.x - 150.0, 10.0, 0.0, 0.0);

iOS - presentViewController like the image (Open iMessages app store in Messages)

I want present a UINavigationController like the image above, I use
nvc.modalPresentationStyle = UIModalPresentationFormSheet;
But I can't change the controller's size.
This is how I did:
UIViewController *vc = [[UIViewController alloc] init];
vc.view.backgroundColor = [UIColor grayColor];
UINavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:vc];
nvc.modalPresentationStyle = UIModalPresentationFormSheet;
nvc.view.frame = CGRectInset(self.view.bounds, 20, 20);
[self presentViewController:nvc animated:YES completion:nil];
But the present viewController is still full screen.
May be you can use preferredContentSize as follows:
nvc.modalPresentationStyle = UIModalPresentationFormSheet;
nvc.preferredContentSize = CGSizeMake(width, height);
Like,
nvc.preferredContentSize = CGSizeMake(300, 600);
OR
In Presented viewController's viewDidLoad method write below code:
self.preferredContentSize = CGSizeMake(width, height);
Edit:
Select your viewController or xib and set size property to Freeform.
Enable user preferred explicit size in Content size in attributes inspector.
For more detail refer answers here:

Presenting UIViewController with clear background

I'm writing iOS FFI methods for Kony application. In that, I'm presenting a viewcontroller with clear backgroundcolor. But, it's showing a white background view. I'm not using storyboars, I'm designing views in code only. In the newviewcontroller viewdidload, I set the self.view background color to clearcolor.
Here's what I have tried,
NewViewController *newVC = [[NewViewController alloc]init];
newVC.providesPresentationContextTransitionStyle = YES;
newVC.definesPresentationContext = YES;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[KonyUIContext onCurrentFormControllerPresentModalViewController:newVC animated:YES];
I'm new to KonyUIContext, how can I fix this?
Can anyone help me on this?
Try this code... It works perfectly for me....
MyViewController *modalViewController = [[MyViewController alloc] init];
modalViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[KonyUIContext presentViewController:modalViewController animated:YES completion:nil];
try this , You just need to set backgroundcolor to clear color of your viewcontroller's view .
NewViewController *newVC = [[NewViewController alloc]init];
newVC.view.backgroundColor = [UIColor clearColor];
newVC.providesPresentationContextTransitionStyle = YES;
newVC.definesPresentationContext = YES;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[KonyUIContext onCurrentFormControllerPresentModalViewController:newVC animated:YES];
Hope this Helps!

How do I make the flip animation on a modal view on the iPad transparent in the background?

How do I make my flip animation transparent so the view behind it is shown through?
Here's some of my code:
EditInfoViewController *editController = [[EditInfoViewController alloc] initWithNibName:#"EditInfoViewController" bundle:nil];
editController.delegate = self;
UINavigationController *editNavController = [[UINavigationController alloc] initWithRootViewController:editController];
editNavController.modalPresentationStyle = UIModalPresentationCurrentContext;
editNavController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self.navigationController presentModalViewController:editNavController animated:YES];
A picture is worth 1000 words (this was taken during the flip animation):

Resources