Position of navigation bar for modal view - iOS7

前端 未结 8 2212
南笙
南笙 2020-11-29 18:08

In a navigation controller, you automatically get the correct colour and position of a navigation bar as expected.

like this

8条回答
  •  攒了一身酷
    2020-11-29 18:56

    In Swift:

    The best way to overcome this in iOS 8.1 and Swift is by conforming to the new UIBarPositioningDelegate protocol.

    You connect the delegate of your NavigationBar to your view controller and conform to that protocol and by calling the method:

    func positionForBar(bar: UIBarPositioning) -> UIBarPosition  {
        return UIBarPosition.TopAttached
    }
    

    You can remove the top gap in the view controller. You need to place the bar 20 points below the top edge.

提交回复
热议问题