UIToolBar背景透明 [英] UIToolBar background transparent
问题描述
我想在 UINavigationBar
中放置 UIToolBar
。
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
的背景颜色是默认蓝色。
但是我需要工具栏应该是清晰的颜色,以便NavigationBar的背景图像也应该出现在该工具栏中。
The background color of that UIToolBar
is the default Blue.
But I need the Toolbar should be in clear color so that the NavigationBar's background image should appear in that Toolbar also.
请建议我。
推荐答案
不确定你在这里做了什么,但你的代码很乱,我认为你可以毫不费力地得到你想要的东西。无论如何,按钮项不应该有工具栏作为其自定义视图。
Not sure what you're after here, but your code is messy, and I think you can get what you want without so much effort. Anyway, a button item should not have a toolbar as its custom view.
如果你的目标是在左边有一个'prev'按钮和'next'按钮在UINavigationBar的右侧,您可以将它们设置为UINavigationItem的 leftBarButtonItem
和 rightBarButtonItem
。没有必要的数组。
If your goal is to have a 'prev' button on the left and a 'next' button on the right of a UINavigationBar, then you can just set them as the UINavigationItem's leftBarButtonItem
and rightBarButtonItem
. No array necessary.
如果你的目标是让'prev'和'next'彼此相邻并且在UINavigationBar的右侧,那么就把它们放进去('然后使用UINavigationItem的 setRightBarButtonItems:animated:
。
If your goal is to have 'prev' and 'next' adjacent to each other and on the right side of the UINavigationBar, then put them ('next' first) in an array and then use UINavigationItem's setRightBarButtonItems:animated:
.
在两种情况下都不是UIToolbar必要。您可以根据Apple的文档将UIToolbar与UINavigationController耦合此处。它弹出屏幕底部,可能不是您想要的,但您可以设置其色调或背景图像。如果您必须将工具栏放在顶部,您可以创建一个并将其手动放置在那里,而不是太难。
In neither case is a UIToolbar necessary. You can couple a UIToolbar with a UINavigationController as per Apple's docs here. It pops up at the bottom of the screen, perhaps not what you want, but you can set its tint or background image. If you must have the toolbar at top, you can create one and place it there manually, not too hard.
祝您好运!
这篇关于UIToolBar背景透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!