我正在编写一个需要生成弹出框以添加新注释的应用程序。为此,我有一些技巧可以解决问题,但是,我似乎无法调整弹出框的大小。这就是我产生它的方式:
UIButton* btn =sender;
UIViewController* fooTroller = [[UIViewController alloc] init];
CGRect rectFoo = CGRectMake(0, 0, 100, 100);
UIView* fooView = [[UIView alloc] initWithFrame:rectFoo];
[fooView setBackgroundColor:[UIColor redColor]];
[fooTroller setView:fooView];
popOver =[[UIPopoverController alloc] initWithContentViewController:fooTroller];
[popOver presentPopoverFromRect:btn.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionLeft
animated:YES];
有什么想法吗?它不尊重 View 大小。
最佳答案
你不应该调用 setView:
在 View Controller 上。让 View Controller 设置自己的 View 。
调整弹出框大小的正确方法是覆盖 contentSizeForViewInPopover
View Controller 的方法来返回大小或设置 popoverContentSize
弹出框上的属性。
UIButton* btn =sender;
UIViewController* fooTroller = [[UIViewController alloc] init];
popOver = [[UIPopoverController alloc] initWithContentViewController:fooTroller];
popOver.popoverContentSize = CGSizeMake(100, 100);
[popOver presentPopoverFromRect:btn.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionLeft
animated:YES];
关于ios - 无法更改 UIPopover 的大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18498371/