我正在尝试将UIToolBar放在UINavigationBar中。
UIToolbar* tempFontSizeToolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(kPaginationToolBarOriginX,kPaginationToolBarOriginY,kPaginationToolBarWidth,kPaginationToolBarHeight)];
tempFontSizeToolBar.backgroundColor = [UIColor clearColor];
// create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] init];
[tempFontSizeToolBar setTranslucent:YES];
UIBarButtonItem *fontSizeBarButtonItem;
fontSizeBarButtonItem = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:KpreviousPageIcon] style:UIBarButtonItemStylePlain target:self action:@selector(movePreviousPage:)];
[buttons addObject:fontSizeBarButtonItem];
[fontSizeBarButtonItem release];fontSizeBarButtonItem = nil;
fontSizeBarButtonItem = [[UIBarButtonItem alloc]
initWithImage:[UIImage imageNamed:KnextpageIcon] style:UIBarButtonItemStylePlain target:self action:@selector(moveNextPage:)];
[buttons addObject:fontSizeBarButtonItem];
[fontSizeBarButtonItem release];fontSizeBarButtonItem = nil;
// stick the buttons in the toolbar
[tempFontSizeToolBar setItems:buttons animated:NO];
[buttons release];buttons = nil;
UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithCustomView:tempFontSizeToolBar];
self.navigationItem.rightBarButtonItem = rightBarItem;该UIToolBar的背景色是默认的蓝色。但我需要的工具栏应该是在清晰的颜色,以便导航栏的背景图像也应该出现在该工具栏。
请推荐我。
发布于 2012-02-22 14:47:58
我不知道你在这里想要什么,但是你的代码很乱,我认为你可以不费太多的力气就能得到你想要的东西。无论如何,按钮项不应该有一个工具栏作为它的自定义视图。
如果您的目标是在UINavigationBar的左侧有一个'prev‘按钮,在右侧有一个'next’按钮,那么您只需将它们设置为UINavigationItem的leftBarButtonItem和rightBarButtonItem即可。不需要数组。
如果您的目标是让“prev”和“next”彼此相邻并且位于UINavigationBar的右侧,那么将它们(“next”)放在一个数组中,然后使用UINavigationItem的setRightBarButtonItems:animated:。
在这两种情况下,都不需要UIToolbar。根据苹果公司的文档here,你可以将UIToolbar与UINavigationController结合使用。它弹出在屏幕的底部,可能不是你想要的,但你可以设置它的色调或背景图像。如果您必须将工具栏放在顶部,您可以创建一个工具栏并手动将其放置在那里,而不是太难。
祝好运!
发布于 2012-12-13 13:53:03
要使工具栏透明,请使用以下方法:
const float colorMask[6] = {222, 255, 222, 255, 222, 255};
UIImage *img = [[UIImage alloc] init];
UIImage *maskedImage = [UIImage imageWithCGImage: CGImageCreateWithMaskingColors(img.CGImage, colorMask)];
[self.toolbar setBackgroundImage:maskedImage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];发布于 2013-07-10 21:40:23
如下所示设置toolbarStyle -1
tools.barStyle = -1; // clear backgroundhttps://stackoverflow.com/questions/9389540
复制相似问题