如何在UIPopoverViewController中添加UIView?

发布于 2025-01-01 12:50:06 字数 47 浏览 1 评论 0原文

如何将 UIView 添加到 UIPopoverViewController 中

How to add the UIView into UIPopoverViewController

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

无需解释 2025-01-08 12:50:06
-(void) buttonAction:(id)sender {
    //build our custom popover view

       UIViewController* popoverContent = [[UIViewController alloc]

                      init];

       UIView* popoverView = [[UIView alloc]

                      initWithFrame:CGRectMake(0, 0, 200, 300)];

       popoverView.backgroundColor = [UIColor whiteColor];

       popoverContent.view = popoverView;


    //resize the popover view shown
    //in the current view to the view's size

       popoverContent.contentSizeForViewInPopover =

                      CGSizeMake(200, 300);


    //create a popover controller

       self.popoverController = [[UIPopoverController alloc]

                   initWithContentViewController:popoverContent];


    //present the popover view non-modal with a
    //refrence to the button pressed within the current view
    [self.popoverController presentPopoverFromRect:popoverButton.frame

                   inView:self.view

                   permittedArrowDirections:UIPopoverArrowDirectionAny

                   animated:YES];


    //release the popover content
    [popoverView release];
    [popoverContent release];
    }

This will add the view to your UIPopoverViewController
-(void) buttonAction:(id)sender {
    //build our custom popover view

       UIViewController* popoverContent = [[UIViewController alloc]

                      init];

       UIView* popoverView = [[UIView alloc]

                      initWithFrame:CGRectMake(0, 0, 200, 300)];

       popoverView.backgroundColor = [UIColor whiteColor];

       popoverContent.view = popoverView;


    //resize the popover view shown
    //in the current view to the view's size

       popoverContent.contentSizeForViewInPopover =

                      CGSizeMake(200, 300);


    //create a popover controller

       self.popoverController = [[UIPopoverController alloc]

                   initWithContentViewController:popoverContent];


    //present the popover view non-modal with a
    //refrence to the button pressed within the current view
    [self.popoverController presentPopoverFromRect:popoverButton.frame

                   inView:self.view

                   permittedArrowDirections:UIPopoverArrowDirectionAny

                   animated:YES];


    //release the popover content
    [popoverView release];
    [popoverContent release];
    }

This will add the view to your UIPopoverViewController
亽野灬性zι浪 2025-01-08 12:50:06

您可以检查下面的链接,了解如何执行此操作

有如何在 iOS 上使用 UIPopoverController 的示例吗?

You can check the following link below to get some idea as to how to do this

Are there examples of how to use UIPopoverController on iOS?

唠甜嗑 2025-01-08 12:50:06

尝试下面的代码:

if (mycontroller == nil) {
            MyController * viewController = [[MyController alloc] initWithNibName:@"ControllerView" bundle:nil];



            mycontroller = viewController;
            PopoverController = [[UIPopoverController alloc] initWithContentViewController:self.mycontroller];    
            PopoverController.delegate = self;
    }

 [PopoverController presentPopoverFromRect:CGRectMake(260, 120, 10, 10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Try the below Code:

if (mycontroller == nil) {
            MyController * viewController = [[MyController alloc] initWithNibName:@"ControllerView" bundle:nil];



            mycontroller = viewController;
            PopoverController = [[UIPopoverController alloc] initWithContentViewController:self.mycontroller];    
            PopoverController.delegate = self;
    }

 [PopoverController presentPopoverFromRect:CGRectMake(260, 120, 10, 10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文