0

Context:

  • UINavigationController with a UITableViewController
  • UISearchController in the navigation bar
  • Navigation bar translucent with black style, it uses large title, tintColor, barTintColor (so no background image).

Issue:

I have a strange animation glitch that shows a hairline above the search bar. The hairline appears only during the scroll.

Screencast

I have already tried many solutions concerning similar problems, but they have not helped.

Tested with an iPhone 7 with iOS 12.1.3

qfwfq
  • 976
  • 11
  • 30

1 Answers1

-1

You can fix hairline issue using this

searchController.searchBar.layer.borderColor = UIColor(red: 242/255.0, green: 82/255.0, blue: 46/255.0, alpha: 1).CGColor
searchController.searchBar.layer.borderWidth = 1

if the above didn’t work. you can remove the hairline completely

extension UINavigationBar {
        func hideBottomHairline() {
            self.hairlineImageView?.isHidden = true
        }

        func showBottomHairline() {
            self.hairlineImageView?.isHidden = false
        }
    }

extension UIView {
    fileprivate var hairlineImageView: UIImageView? {
        return hairlineImageView(in: self)
    }

    fileprivate func hairlineImageView(in view: UIView) -> UIImageView? {
        if let imageView = view as? UIImageView, imageView.bounds.height <= 1.0 {
            return imageView
        }

        for subview in view.subviews {
            if let imageView = self.hairlineImageView(in: subview) { return imageView }
        }

        return nil
    }
}
karthik
  • 621
  • 4
  • 14
  • First of all I'm using `UISearchController` instead of `UISearchDisplayController`, in any case, thanks but it does not help. Furthermore, what is the `self.hairlineImageView` property? – qfwfq Feb 04 '19 at 08:13
  • Search bar border does not help because the hairline appears above, please open https://duaw26jehqd4r.cloudfront.net/items/3y1p3j252B1Z3912422V/IMG_3044-2.png Image view `hairlineImageView` is found and hidden, but the problem remains. The only way so far observed to not have the problem is to set the navigation bar as opaque. – qfwfq Feb 04 '19 at 09:19
  • https://stackoverflow.com/questions/38355288/change-navigation-bar-bottom-border-color-swift for the least solution, you can try change that bottom hairline color. – karthik Feb 04 '19 at 11:16