UIButton UIPopUpController 以编程方式
难以显示 UIButton
项目。我想在我的 UIPopUpController
中放置几个 UIButton
。我正在故事板中完成所有操作,并且我需要以编程方式完成此部分。
- (void)showPopover:(id)sender
{
if(![popoverController isPopoverVisible])
{
myPopOver = [[PopUp alloc] init];
popoverController = [[UIPopoverController alloc] initWithContentViewController:myPopOver] ;
[popoverController setPopoverContentSize:CGSizeMake(300, 200.0f)];
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
CGRect rect = (CGRect)[sender frame];
rect.origin.y = self.view.frame.size.height - rect.size.height;
[popoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else
{
[popoverController dismissPopoverAnimated:YES];
}
}
having difficulty getting UIButton
Items to show.. I want to place several UIButtons
within my UIPopUpController
. I'm doing everything in a storyboard and I need to do this section programmatically.
- (void)showPopover:(id)sender
{
if(![popoverController isPopoverVisible])
{
myPopOver = [[PopUp alloc] init];
popoverController = [[UIPopoverController alloc] initWithContentViewController:myPopOver] ;
[popoverController setPopoverContentSize:CGSizeMake(300, 200.0f)];
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
CGRect rect = (CGRect)[sender frame];
rect.origin.y = self.view.frame.size.height - rect.size.height;
[popoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
else
{
[popoverController dismissPopoverAnimated:YES];
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 UINavigationController(它已经有一个导航栏,您可以在其中附加按钮项)并将其添加为 UIPopoverController 的内容。 UINavigationController 可以使用 initWithRootViewController 方法进行实例化。在这种情况下,控制器将是您的 Popup 类。例如,在 showPopover 方法中,您可以执行以下操作:
现在,在 PopUp 类中的 viewDidLoad 方法中,您可以自定义 UINavigationController 导航栏。例如:
其中somethingSelector 如下所示:
编辑
或者,您可以避免使用 UINavigationController 并在 PopUp 类中创建 UIToolbar。在 UIToolbar 内部,您可以附加 UIBarButtonItems。请参阅 UIToolbar 类参考
You could use a UINavigationController (it has already a navigation bar where you can attach buttons items) and add it as the content of your UIPopoverController. The UINavigationController can be istantiated using the initWithRootViewController method. In this case the controller would be your Popup class. For example, inside your showPopover method, you could do the following:
Now, inside your PopUp class, within viewDidLoad method, you can customize the UINavigationController navigationBar. For example:
where somethingSelector is like the following:
EDIT
Alternatively you can avoid to use the UINavigationController and create UIToolbar inside your PopUp class. Inside the UIToolbar you can attach UIBarButtonItems. See UIToolbar Class Reference