自定义 Table 故事板中的视图单元格布局似乎无效

custom Table View Cell layout in storyboard seems invalid

我自定义故事板中的 table 视图单元格以在单元格中创建标签中心。

不过好像没什么感情

我的故事板是这样的:

实际上是这样的:

我只在这样的代码中设置标签的文本:

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Movie", for: indexPath) as! ArchiveTableViewCell
    cell.showChineseTitle.text = chineseTitleArray[indexPath.row]

    return cell
}

为什么?

提前致谢!!!

尝试添加:

cell.showChineseTitle.textAlignment = .center

因为您没有为 UILable 正确设置文本对齐方式。但只能设置它在单元格中的位置。

删除前导和顶部约束并设置宽度和高度约束以使标签在单元格中居中。将标签的 textAlignment 属性 设置为居中。