【问题标题】:White line under UINavigationBar in IOS 7IOS 7中UINavigationBar下的白线
【发布时间】:2013-11-08 06:46:30
【问题描述】:

我有一个UITableViewController 和一个UISearchDisplayControllerUISearchBar。当我在 UITabBarController 中显示视图时,我在导航栏下方看到一条白线。当我在UINavigationController 中以模态方式呈现视图时,这条线要么是灰色的,要么是黑色的(我不知道),它看起来非常正常。有什么想法吗?

【问题讨论】:

    标签: ios iphone objective-c ios7 uikit


    【解决方案1】:

    我遇到了同样的问题,不知道它是从哪里来的(它无处不在,不是shadowImage),最终得到了以下修复(在我的UINavigationController 子类中)

    // Fixes strange line under NavigationBar
    {
        UIView * view = [[UIView alloc] init];
        view.backgroundColor = self.navigationBar.barTintColor;
        CGRect rect = view.frame;
        rect.origin.x = 0.f;
        rect.origin.y = self.navigationBar.frame.size.height;
        rect.size.width = self.navigationBar.frame.size.width;
        rect.size.height = 1.f;
        view.frame = rect;
        [self.navigationBar addSubview:view];
    }
    

    【讨论】:

      【解决方案2】:

      我也遇到了同样的问题,尝试了很多方法后,我发现这种方法解决了我的问题

      [[UISearchBar appearance] setBackgroundColor:[UIColor yourColor]];
      

      把它写在你的 viewDidLoad 中。

      【讨论】:

      • 在 iOS 9 中为我工作,谢谢!
      【解决方案3】:

      白线大概是导航栏的shadowImage

      尝试将其设置为:

      self.navigationController.navigationBar.shadowImage = [UIImage new];
      

      【讨论】:

        【解决方案4】:

        尝试将 UISearchBar 上的 clipsToBounds 属性设置为 YES。

        【讨论】:

        • 很遗憾,这并没有解决问题。
        【解决方案5】:

        使用以下代码行:

        UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 43, 320, 1)];
        [overlayView setBackgroundColor:[UIColor whiteColor]];   // set color accordingly
        [navBar addSubview:overlayView]; // navBar is your UINavigationBar instance
        [overlayView release];
        

        这是我发布的答案: Horizontal Separator NavBar IOS 7

        How to remove UINavigatonItem's border line

        【讨论】:

          【解决方案6】:

          Divya 答案的 Swift 版本

              let hideLineView = UIView(frame: CGRect(x: 0, y: navigationController!.navigationBar.frame.size.height, width: view.frame.size.width, height: 1))
              hideLineView.backgroundColor = UIColor.white
              navigationController!.navigationBar.addSubview(hideLineView)
          

          【讨论】:

            猜你喜欢
            • 2014-03-20
            • 1970-01-01
            • 2013-09-25
            • 2014-07-19
            • 2013-09-20
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多