2011-05-18 55 views
7

在iPad应用程序中,我希望能够在弹出窗口的顶部栏中有多个按钮。我启动它是这样的:自定义UIPopoverController中的titleView

UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc]; 

pop = [[UIPopoverController alloc] initWithContentViewController:nc]; 
[pop presentPopoverFromRect:CGRectInset([tableView rectForRowAtIndexPath:indexPath], 10, 10) 
        inView:tableView 
    permittedArrowDirections:UIPopoverArrowDirectionAny 
        animated:YES]; 
pop.delegate = self; 
[nc release]; 

viewDidLoad我想设置于titleview包含多个UIBarButtonItems。这在正常的UINavigationController上没问题,但我需要能够做到这一点,并保持导航栏的自定义样式在弹出窗口上。

我已经尝试设置rightBarButtonItem有一个包含按钮的工具栏,但它们采用工具栏的格式,它本身不会采用弹出窗口的格式/样式。

+0

你可以指定“格式/风格”是什么意思,你如何将它们设置为弹出? – Zapko 2011-05-31 06:56:02

+0

忽略我的问题一分钟,创建一个导航控制器在其中的popover。你会看到按钮的光芒自动匹配边框/箭头的光芒。现在,设置一个导航。控制器按钮是一个比如说UIToolBar(通常会把多个按钮放进去)。该工具栏中按钮的格式将不符合弹出窗口的光泽。 – Lee 2011-06-01 09:48:14

回答

1

这是一个有点hackish,但你可以创建子类化和压倒一切的drawRect一个真正透明的UIToolbar:用空的方法。这仍然会在工具栏上绘制UIBarButtonItems,而不是工具栏本身。

然后,如Nils所述,您可以从自定义工具栏实例中创建一个条形按钮项并将其添加为rightBarButtonItem。

0

为什么不使用自定义UIViewUIToolbarUINavigationBar而不是UIPopoverController

效果,是一样的

+0

因为popover增加了它自己的光泽,箭头等。全部免费。如前所述,它也以光泽为主题的工具栏/导航栏 - 所以不一样。 – Lee 2011-05-26 10:08:41

+0

@李正确,但它是一个简单的选择! :)阅读此:http://stackoverflow.com/q/4769169/88461 – elp 2011-05-26 10:30:23

0

首先你需要设置一个委托给UINavigationController,然后实现nabigationController:willShowViewController:animated:method。在这种方法中,您可以调整左右栏按钮项目。

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{ 

    viewController.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] 
                 initWithTitle:@"Image Source" 
                 style:UIBarButtonItemStylePlain 
                 target:self 
                 action:@selector(cancelPressed)] autorelease]; 
} 
+0

这不是回答这个问题。我特别想使用多个按钮来定制左/右栏按钮项目视图,并让视图样式向下钻取。 – Lee 2011-05-30 10:56:36

0

我有同样的问题,这里是我做过什么:

UIBarButtonItem *uiBarRefresh = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(forcerefresh)]; 
UIBarButtonItem *uiBarCurl = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemPageCurl target:self action:@selector(showlist)]; 

UIToolbar_transparent* tools = [[UIToolbar_transparent alloc] initWithFrame:CGRectMake(0, 0, 133, 44.01)]; 
tools.barStyle = UIBarStyleBlackTranslucent; 
tools.translucent = YES; 
tools.backgroundColor = [UIColor clearColor]; 
tools.tintColor = self.navigationController.navigationBar.tintColor; 
[tools setItems:[NSArray arrayWithObjects:flexItem,uiBarRefresh,uiBarCurl,nil] animated:NO]; 
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools]; 

这样,你避免了暗灰色的背景,讨厌白色的下划线,你可以完全自定义如何希望他们通过使用固定或柔性间隔来定位。

祝您好运与您的项目:]

+0

耻辱你错过了那里的赏金。我唯一的问题是...你的UIToolbar_transparent是一切。如果有,是否可用?这样做与UIToolbar正常的结果在http://cl.ly/7Gky – Lee 2011-06-02 06:06:41

+0

是的,但这是真正的透明,看起来相当不错:] – 2011-06-02 09:17:23

+0

我的问题是 - 该类可用在任何地方;) – Lee 2011-06-02 11:39:32

相关问题