ios 7中工具栏的顶部边缘出现一条像素的细线

时间:2014-03-05 06:50:36

标签: ios objective-c ios7 uitoolbar

我将我的应用程序从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的顶部边缘出现了一条像素的细线,但它很烦人,如果有人不想要它会被移除。

删除该行的任何解决方案?

看起来像这样

how it looks like

2 个答案:

答案 0 :(得分: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];
            }
        }

解决了我的问题。

答案 1 :(得分:0)

使用Storyboards ....方便地跟踪那些东西......没有额外的应用程序。这是iPhone故事板的快照。左侧的视图,按钮,标签层次结构.....属性检查器' Xcode screenshot

右侧的视图,按钮和标签的单独调整