ios 11 custom navbar goes under status bar

前端 未结 5 1705
刺人心
刺人心 2020-11-28 13:31

just downloaded xcode 9 and i\'m having this weird issue, on ios 11 my custom navbar appears to be half in size and is under the status bar, on ios 10 works fine.

so

5条回答
  •  盖世英雄少女心
    2020-11-28 14:14

    Try adding some Auto Layout constraints after you add the nav bar to the view

    if #available(iOS 11.0, *) {
        newNavbar.leadingAnchor.constraint(equalTo: view.leadingAnchor).isActive = true
        newNavbar.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true
        newNavbar.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true
        newNavbar.heightAnchor.constraint(equalToConstant: 64).isActive = true
    }
    

    You can actually use all but the third constraint in earlier versions of iOS but if it all works in earlier versions you may not want to mess with it.

    Using the safe layout area should keep your nav bar under the status bar.

提交回复
热议问题