【发布时间】:2014-05-28 02:22:56
【问题描述】:
我将我的应用从 xcode 4.6 切换到 5。
我在导航栏右侧添加了 UIToolBar,有 3 个按钮,我为此使用了以下代码。
UIToolbar* tools = [[UIToolbar alloc] initWithFrame:CGRectMake(0, -25, 135, 44)];
//[tools setTintColor:[UIColor colorWithRed:54/255.0f green:54/255.0f blue:54/255.0f alpha:0.0]];
[tools setBackgroundColor:[UIColor clearColor]];
//[tools setBarTintColor:[UIColor whiteColor]];
[tools setAlpha:0.0f];
[tools setClearsContextBeforeDrawing:YES];
[tools setTintColor:[UIColor clearColor]];
[tools setTranslucent:YES];
[tools setBackgroundImage:[UIImage imageNamed:@"historyBg.png"] forToolbarPosition:UIToolbarPositionTop barMetrics:UIBarMetricsDefault];
[tools setShadowImage:[UIImage imageNamed:@"historyBg.png"] forToolbarPosition:UIToolbarPositionTop];
// Create the array to hold the buttons, which then gets added to the toolbar
NSMutableArray* buttons = [[NSMutableArray alloc] initWithCapacity:2];
//Create volume control button
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 30, 30);
[button addTarget:self action:@selector(volumeControlButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
button.showsTouchWhenHighlighted = YES;
[button setBackgroundImage:[UIImage imageNamed:@"icnVolumeControl.png"] forState:UIControlStateNormal];
UIBarButtonItem* bi = [[UIBarButtonItem alloc] initWithCustomView:button];
volumeControl = bi;
[buttons addObject:bi];
//Creates mute volume control button
btnToggleMute = [UIButton buttonWithType:UIButtonTypeCustom];
btnToggleMute.frame = CGRectMake(0, 0, 30, 30);
[btnToggleMute addTarget:self action:@selector(ToggleSound:) forControlEvents:UIControlEventTouchUpInside];
btnToggleMute.showsTouchWhenHighlighted = YES;
[btnToggleMute setBackgroundImage:[UIImage imageNamed:@"icnMuteVolume.png"] forState:UIControlStateNormal];
[btnToggleMute setBackgroundImage:[UIImage imageNamed:@"icnNotMute.png"] forState:UIControlStateSelected];
bi = [[UIBarButtonItem alloc] initWithCustomView:btnToggleMute];
[buttons addObject:bi];
button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 30, 30);
[button addTarget:self action:@selector(playLastPlayedVideo:) forControlEvents:UIControlEventTouchUpInside];
button.showsTouchWhenHighlighted = YES;
[button setBackgroundImage:[UIImage imageNamed:@"icnQuickPlay.png"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"icnQuickPlay@2x.png"] forState:UIControlStateSelected];
bi = [[UIBarButtonItem alloc] initWithCustomView:button];
[buttons addObject:bi];
// stick the buttons in the toolbar
[tools setItems:buttons animated:NO];
// and put the toolbar in the nav bar
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:tools];
问题是在 iOS 7 中顶部边缘出现一像素细线。我尝试了所有功能背景颜色、色调颜色、阴影图像等。没有解决我的问题。
我也提到了这个transition guidelines for bars in ios 7。
我发现在针对外观属性的 Bars 部分中提到,iOS 7 的顶部边缘出现一像素细线,但这很烦人,如果有人不希望它被删除。
有什么办法可以去掉那条线吗?
看起来像这样
【问题讨论】:
-
尝试使用revealapp.com 调查视图层次结构,它会有所帮助。
-
像这样删除阴影图像没有帮助?
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault]; [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]]; -
@MANIAK_dobrii thanx,一个很棒的工具,我不知道那个工具,它表明它是 UIToolBar 本身的一部分。但无法找到问题的根源。
-
@iNoob thanx 感谢您的快速回复,但这并没有解决我的问题。
标签: ios objective-c ios7 uitoolbar