Make Popover Background Black in Interface Builder - iphone

I've successfully hooked up several popover views in interface builder. I've tried to make the background black by setting the view background color to black, but I am still getting a white arrow on the popover itself and white artifacts on the 4 rounded corners.
Please see the screenshot.
What can I do to make the background totally black in interface builder?
I appreciate the answer below but I still can't quite get it to work - here is my code:
// Show the satellite Ephemeris
if ( itemIndex == 1 ) {
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
NSLog(#"This is an iPad - Creating popover!");
EphemerisDataView *ephemView = [[EphemerisDataView alloc] init];
UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:ephemView];
[popOver setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
[popOver.popoverBackgroundViewClass setTintColor:[UIColor blackColor]];
CGSize size = CGSizeMake(320, 480); // size of view
popOver.popoverContentSize = size;
[popOver presentPopoverFromRect:self.popOverAnchor.bounds inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else {
NSLog(#"This is not an iPad - Performing segue...");
// Show the next view
[self performSegueWithIdentifier:#"Ephemeris" sender:self];
}
}

You cannot customize that arrow by IB. You will need a totally customized popover for you. Plenty of them are available on git. But If you want to use default one then it is not possible to customize that arrow as well.

Do it like this:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
NSLog(#"This is an iPad - Creating popover!");
UIStoryboard *storyboard = [UIStoryboard storyboardWithName: #"MainStoryboard_iPad" bundle:[NSBundle mainBundle]];
EphemerisDataView *ephemView = [storyboard instantiateViewControllerWithIdentifier:#"EphemerisDataView"];
UIPopoverController *popOver = [[UIPopoverController alloc] initWithContentViewController:ephemView];
self.customPopoverController = popOver;
[popOver setPopoverBackgroundViewClass:[DDPopoverBackgroundView class]];
[popOver.popoverBackgroundViewClass setTintColor:[UIColor blackColor]];
popOver.delegate = self;
CGSize size = CGSizeMake(320, 480); // size of view
popOver.popoverContentSize = size;
[popOver presentPopoverFromRect:self.popOverAnchor.bounds inView:self.popOverAnchor
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else {
NSLog(#"This is not an iPad - Performing segue...");
// Show the next view
[self performSegueWithIdentifier:#"Ephemeris" sender:self];
}

Related

UIPopoverController is showing on the other button

When UIButton is tapped to display UIPopovercontroller, it is showing on the other UIbarbuttonitemand it is showing blank black opaque UIPopovercontroller.
Here is my implemented code:
- (IBAction)buttonTapped:(id)sender {
UIButton *btnAction;
BookmarkViewController* bookmarkVC = [[BookmarkViewController alloc] init];
_buttonPopoverController = [[UIPopoverController alloc]
initWithContentViewController:bookmarkVC];
_buttonPopoverController.delegate = self;
CGRect popoverFrame = btnAction.frame;
[_buttonPopoverController setPopoverContentSize:CGSizeMake(320, 355) animated:NO];
//only required if using delegate methods
[_buttonPopoverController presentPopoverFromRect:popoverFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
UIButton *btnAction=(UIButton*) sender;
You are missing to assing sender to btnAction
that is UIButton *btnAction=(UIButton *)sender;
try this,
- (IBAction)buttonTapped:(id)sender {
UIButton *btnAction=(UIButton *)sender;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
UIViewController *bookmarkVC = [storyboard instantiateViewControllerWithIdentifier:#"BookmarkViewController"];
_buttonPopoverController = [[UIPopoverController alloc]
initWithContentViewController:bookmarkVC];
_buttonPopoverController.delegate = self;
CGRect popoverFrame = btnAction.frame;
[bookmarkVC setContentSizeForViewInPopover:CGSizeMake(320, 355)];
//only required if using delegate methods
[_buttonPopoverController presentPopoverFromRect:popoverFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
Your issue is here
[_buttonPopoverController presentPopoverFromRect:popoverFrame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
where presentPopoverFromRect:popoverFrame should be actually the rect of the popover not of the UIButton and also the btnAction has no frame you haven't allocated it also and you are performing CGRect popoverFrame = btnAction.frame;
It should be like
[popover presentPopoverFromRect:CGRectMake(0.0, 0.0, 300.0, 50.0) inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Hope this helps.

How can i use popover controller in UIPageViewController?

Can i use the popover controller to get back to previous view controllers in page view controller. Is there any method to do so.
This code i am trying.
-(void)goNext
{
Vcontr = [self.pageController.viewControllers objectAtIndex:0];
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:pageController];
if(popoverController == nil){ //make sure popover isn't displayed more than once in the view
popoverController = [[UIPopoverController alloc] initWithContentViewController:pageController];
}
[popoverController presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
popoverController.delegate = self;
}
Here are some tutorials:
iPad for iPhone Developers 101: UIPopoverController Tutorial
iPad UIPopoverController Video
and read Apple developers
and you can find sample code by Apple developers
UIPopoverController *popoverController ;///defin this in the .h
if(popoverController == nil){ //make sure popover isn't displayed more than once in the view
popoverController = [[UIPopoverController alloc] initWithContentViewController:yourPageViewController];
}
[popoverController presentPopoverFromRect:self.view.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
popoverController.delegate = self;
}

UIPopoverController disappears when ipad orientation changes

Popover appears properly when I click on button.
When orientation changes then it disappears & leave a black topbar.
Below is the reference image.
Can anyone suggest, why it is happening?
My Code:
EBFirstViewController *firstViewController = [[EBFirstViewController alloc]init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:firstViewController];
navigationController.delegate = self;
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navigationController];
self.popoverController = popover;
popoverController.delegate = self;
[popoverController setPopoverContentSize:CGSizeMake(320.0f, 527.0f)];
[popoverController presentPopoverFromRect:settingsBtn.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
For That following code help to solve your problem.
- (void)application:(UIApplication *)application willChangeStatusBarOrientation:(UIInterfaceOrientation)newStatusBarOrientation duration:(NSTimeInterval)duration {
// a cheat, so that we can dismiss all our popovers, if they're open.
if (ObjPopover) {
// if we're actually showing the menu, and not the about box, close out any active menu dialogs too
if (menuPopoverVC && menuPopoverVC == ObjPopover.contentViewController)
[menuPopoverVC.popoverController dismissPopoverAnimated:YES];
[menuPopoverPC dismissPopoverAnimated:YES];
menuPopoverPC = nil;
}
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {
// the user (not us) has dismissed the popover, let's cleanup.
ObjPopover = nil;
}

how to get a popover frame of specified width and height in ipad

i am using an popover view in my application,when i went through the samples i found how to create a popover view but in the sample code the popover view is getting displayed to whole page. i want the popover frame of specified width and height when i click the button.
-(IBAction) settingsGo:(id) sender{
NSLog(#"Go");
if (self.popoverController == nil)
{
PopOver *lang = [[PopOver alloc]
initWithNibName:#"PopOver" bundle:[NSBundle mainBundle]];
UIPopoverController *popOver =
[[UIPopoverController alloc]initWithContentViewController:lang];
popOver.delegate = self;
[lang release];
self.popoverController = popOver;
[popOver release];
}
CGRect popoverRect = [self.view convertRect:[button frame]fromView:[button superview]];
popoverRect.size.width = MIN(popoverRect.size.width, 50);
[self. popoverController
presentPopoverFromRect:popoverRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
so what changes i should make in the above code to get a frame of specified size of width and height.
Account is the class to be displayed. popAccount is its instance. buttonA is the button on which after click the popOver will be displayed.
-(void)viewDidLoad
{
popAccount = [[Account alloc] init];
//[popAccount setDelegate:self];
popOverControllerA = [[UIPopoverController alloc] initWithContentViewController:popAccount];
popOverControllerA.popoverContentSize = CGSizeMake(200, 200);
}
-(IBAction)togglePopOverControllerA {
if ([popOverControllerA isPopoverVisible]) {
[popOverControllerA dismissPopoverAnimated:YES];
} else {
[popOverControllerA presentPopoverFromRect:buttonA.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
}
Further ask for any query..
Set popoverController.popoverContentSize to whatever size you want.
In the root view to position
CGRect frame= CGRectMake(0,0, 0, 0);
[self.myPickerPopover presentPopoverFromRect:frame inView:self.view permittedArrowDirections:0 animated:NO];
To size in the view controller contents being displayed in the popover
-(void)viewDidLoad
{
self.contentSizeForViewInPopover = CGSizeMake(750,880);
}

how to show the UIPopoverController when button clicked in iPhone

I have a problem with UIPopoverController. On button press I need to display the UIPopoverController. This is the code.
-(IBAction)hintButton:(id)sender{
CGRect contentRect = CGRectMake(0, 0, 200, 40);
UIViewController* popoverContent = [[UIViewController alloc] init];
popoverContent.view = hintB;
popoverContent.contentSizeForViewInPopover = contentRect.size;
if(popoverController == nil){ //make sure popover isn't displayed more than once in the view
popoverController = [[UIPopoverController alloc]initWithContentViewController:popoverContent];
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
popoverController.delegate = self;
}
}
When I press the button application crashes.
UIPopoverController cannot be used for iPhone applications. It's only for iPad apps.
However, you can have this functionality by creating custom UIPopoverController. You can find a custom UIPopoverController sample here.
Let me know if you have any similar questions.
Thanks,
MinuMaster