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

时间:2017-04-26 12:53:02

标签: ios swift uitableview uistoryboard

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

但似乎没有感情。

我的故事板是这样的:

enter image description here

实际上它是这样的:

enter image description here

我只在代码中设置标签文字,如下所示:

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
}

为什么?

提前致谢!!!

2 个答案:

答案 0 :(得分:0)

尝试添加:

cell.showChineseTitle.textAlignment = .center

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

答案 1 :(得分:0)

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

enter image description here