【问题标题】:A one-pixel hairline appears at the top edge of toolbar in ios 7ios 7 工具栏顶部边缘出现一像素细线
【发布时间】: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


【解决方案1】:

感谢 MANIAK_dobrii 提出了一个很棒的工具 revealapp,在该工具的帮助下,我发现在 UIToolBar 子视图层次结构中,有一个 UIImageView 导致 UIToolBar 顶部出现灰色线条。

我使用以下代码使其不可见

    [tools setBarTintColor:[UIColor clearColor]];
    for(UIView *view in [tools subviews])
        {
            if([view isKindOfClass:[UIImageView class]])
            {
                [view setHidden:YES];
                [view setAlpha:0.0f];
            }
        }

并解决了我的问题。

【讨论】:

    【解决方案2】:

    使用情节提要....无需额外的应用程序即可轻松跟踪这些内容。这是 iPhone 故事板的快照。左侧的视图、按钮、标签层次结构......在“属性检查器”中对右侧的视图、按钮和标签进行单独调整

    【讨论】:

    • 通过使用左侧的视图层次结构,您无法在工具栏或其他 uicontrols 中看到子视图(内置或默认)。在这里故事板没有任何区别。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-29
    • 2021-12-29
    相关资源
    最近更新 更多