我已經有了一個UITableView,並且這個單元通過對遠程服務的post調用來填充。 我已經將UILabel lineBreakMode屬性設置爲NSLineBreakByTruncatingTail
,並將行設置爲2.在單元格xib上,一切似乎都很好。這裏是截圖:UILabel應該會產生省略號但不起作用
這是一段代碼我使用填充後解析從遠程服務中檢索到的JSON的文本。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (posts.count == 0){
return tableView.dequeueReusableCell(withIdentifier:
TableViewCellIdentifiers.emptyCell, for: indexPath)
} else {
let cell = tableView.dequeueReusableCell(withIdentifier:
TableViewCellIdentifiers.postCell, for: indexPath) as! PostCell
let post = posts[indexPath.row]
cell.userNameLabel.text = post.userName
cell.postTextLabel.text = post.text
cell.timeLabel.text = post.time
cell.distanceLabel.text = post.distance
return cell
}
}
任何想法的問題,其中可能呢?
缺少約束來告訴你的標籤它不能超過一定的寬度(比如時間標籤或距離標籤之前的8個點)?此外,您可能還想檢查關於Y位置或高度的黃色警告,並查看結果(修復它,並且可能爲字體大小添加適合的縮放比例) – Larme
xib中的橙色線意味着有問題。你可能只是設定框架,而不是約束。 – Sulthan