3

I'm trying to set the contentInsetAdjustmentBehavior == .never for the UITableView in the viewDidLoad() of the ViewController, however it is ignored, no matter if I do it programmatically or via the InterfaceBuilder.

Here is what I get. The image is the header of the TableView.

Here is what I get. The image is the header of the TableView.

I have the navigation bar on top of that which is transparent by the way.

I expect the Header with the image to be like this

expected behavior

Any help's appreciated. Thanks

Shezad
  • 756
  • 7
  • 14

1 Answers1

1

enter image description hereSet the topConstraint constant of imageView to -64

  • create an Outlet for topConstraint of imageView
  • declare a variable topPadding (for iPhone X)

    @IBOutlet weak var topConstraint: NSLayoutConstraint!
    var topPadding:CGFloat = 0.0
    

And use the below code in viewDidload

override func viewDidLoad() {
    super.viewDidLoad()

    self.navigationController!.navigationBar.setBackgroundImage(UIImage(), for: .default)
    self.navigationController!.navigationBar.shadowImage = UIImage()
    self.navigationController!.navigationBar.isTranslucent = true
    topConstraint.constant = -64
    if #available(iOS 11.0, *) {
        let window = UIApplication.shared.keyWindow
        topPadding = (window?.safeAreaInsets.top)!
        topConstraint.constant = -(64+topPadding)
    }
}

Refer this sample project

Shezad
  • 756
  • 7
  • 14
  • Well, basically it helps ( adding the constraint) . But in this case the image is too big for 5s, and looks bad on iPhone X. And the property 'contentInsetAdjustmentBehavior == .never' is not set. Maybe, there are some conflicting proprieties or constraints which do not allow me to do the expected way? Do you know? P.S all of this, except for the topConstraint, I have already tried. – Nikita Krasnov Sep 04 '18 at 10:54
  • @NikitaKrasnov so you could reduce the image height while you set topConstraint to -64 – Shezad Sep 04 '18 at 10:56
  • @NikitaKrasnov in case of iPhone X you have to add top padding also – Shezad Sep 04 '18 at 11:01
  • @NikitaKrasnov I have updated the above code and project in the GitHub solving the iPhone X issue – Shezad Sep 04 '18 at 11:32