Translucent Status Bar with No Navigation Bar

前端 未结 2 1110
孤城傲影
孤城傲影 2021-01-01 01:06

Goal: To have a table view scroll so that it shows semitransparent under the status bar while not displaying a navigation bar.

Right now, I have my tableView set to

2条回答
  •  一整个雨季
    2021-01-01 01:26

    As you described, your UITableView is right underneath the status bar. When you scroll down, the tableView's frame remains the same size and origin and won't go underneath the status bar. What you want to do is to set the constraint for your tableView to the top of the superview (not the Top Layout Guide) which means it would sit right under the status bar.

    Because the status bar now hides the top 20px of your tableView you want to make a content offset:

    tableView.contentInset = UIEdgeInsetsMake(top: 20, left: 0, bottom: 0, right: 0)
    

    To make the scroll indicator start right under the status bar you also want to set an offset for it:

    tableView.scrollIndicatorInsets = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
    

提交回复
热议问题