2014-11-04 61 views
0

我建立一個自定義的表格單元格:在iPhone 5如何對齊UITableViewCell內的不同屏幕尺寸的內容?

enter image description here

class CustomTableViewCell: UITableViewCell { 

    @IBOutlet weak var streetLabel: UILabel! 
    @IBOutlet weak var cityLabel: UILabel! 
    @IBOutlet weak var priceLabel: UILabel! 

    func loadItem(#street: String, city: String, price: String){ 
     self.streetLabel.text = street 
     self.cityLabel.text = city 
     self.priceLabel.text = price 
    } 
} 

結果:

enter image description here

結果在iPhone 6+

enter image description here

正如您所看到的,單元格的左側顯示正確,它會粘到左側。然而,右側應該堅持正確的做法,但事實並非如此。所以這裏是我的問題:

  • 如何將單元格的寬度設置爲tableView的寬度,以便單元格具有與屏幕相同的寬度?
  • 我怎樣才能讓右側實際上粘在表格單元的右側?
+0

您使用的是自動佈局? – 2014-11-04 15:46:34

+0

@CleverError是的,我願意! – 2014-11-04 15:48:20

回答

1

UITableViewCells總是和UITableView一起使用,所以需要注意的是,

根據你張貼,它看起來並不像你的截圖目前正在使用自動佈局來定位標籤。您需要做的僅僅是將價格標籤右側的約束添加到單元右側。然後,當細胞生長時,您的標籤將保持與細胞右邊緣相同的距離。

您對頂部標籤的限制應該如下所示。

enter image description here