2017-04-25 44 views

回答

2

我假設你正在使用Autolayout這樣你既可以約束的tableView的.top保證金其超視圖的.top或視圖控制器的topLayoutGuide財產以便表格視圖將從0開始:

let toItem: Any = self.topLayoutGuide 
// You can change this to `self.view` to have the same effect. 

view.addConstraint(
    NSLayoutConstraint(item: tableView, 
    attribute: NSLayoutAttribute.top, 
    relatedBy: NSLayoutRelation.equal, 
    toItem: toItem, 
    attribute: NSLayoutAttribute.top, 
    multiplier: 1.0, constant: 0 
) 
) 

這裏是如何看起來在我的模擬器:

enter image description here

要使狀態欄下的表頭開始,只要使用layoutGuide.bottom屬性,而不是.top

enter image description here

在這裏你可以download的測試項目。

+0

太好了。我正在向layoutGuide的頂部添加.top,而不是SuperView –

相關問題