我已经有了一个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