Set UIPopOverController Size

I have a view with a bunch of buttons in a UIScrollView . When the user clicks the button, I want the UIPopOverController to display a pointer to the selected button. This seems to work, but the popover is the wrong size and points to a random point in the view. Here is my code

 -(void)detail:(id)sender{ UIButton *button = sender; NSLog(@"tag = %i", button.tag); UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController]; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { self.popover = [[UIPopoverController alloc] initWithContentViewController:navController]; self.popover.delegate = self; [self.popover presentPopoverFromRect:button.bounds inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; } 

What is the problem with the size of the popover: In the view that is inside the popover, I have:

 self.contentSizeForViewInPopover = scroll.contentSize; NSLog(@"%f, %f", scroll.contentSize.height, scroll.contentSize.width); NSLog(@"showing: %f, %f", self.contentSizeForViewInPopover.height, self.contentSizeForViewInPopover.width); 

and both logs match. Therefore, I think that everything should work correctly. But this is not so. Here is a screenshot. Let me know if you need more of my code. Thank you in advance.

screen shot of the error

+5
iphone ipad uiscrollview popover uipopovercontroller
Jul 21 2018-11-11T00:
source share
2 answers

As for just the size of popover: I managed to do this with a variable UILabel with a variable height:

 UILabel *hinweis; hinweis.text = @"..."; hinweis.frame = CGRectMake(x,y,width,800); [hinweis sizeToFit]; 

And for the arrow: have you tried another inView parameter like self.parentViewController.view?

+1
Jul 24. '11 at 16:26
source share

The first thing I noticed is that you should use the button.frame button, not button.bounds for the rectangle. The difference between these UIView properties:

The geometry of the representation is determined by its frame, boundaries, and the center of the property. The frame property determines the origin and dimensions of the view in the coordinate system of its observation and is usually used during layout to adjust the size or position of the view.

The bounds property determines the internal dimensions of the view, since it sees them and is used almost exclusively in custom drawing code.

You can set the height of your popover controller using the setPopoverContentSize message:

 // so something like this ... [self.popover setPopoverContentSize:CGSizeMake(320, 460)]; // and to bind the popover to your button [self.popover presentPopoverFromRect:button.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]; 
+23
Jul 21 2018-11-11T00:
source share



All Articles