2017-04-03 36 views
0

我无法设法让我的文本对齐到我的表视图的右侧。我的代码将文本对齐设置为正确,但只有当该行多出一行时才能证明文本正确。这是我的cellforRowAt代码textAlignent在Swift 3.0的cellForRowAt中的右边

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 


    let cell = UITableViewCell(style: .subtitle, reuseIdentifier: cellId) 
    cell.textLabel?.text = self.messages[indexPath.row] 
    cell.textLabel?.numberOfLines = 0 
    cell.textLabel?.textAlignment = .right 
    return cell 
} 

我该如何解决这个问题?

回答

0

你正在使用字幕UITableViewCell风格是不是?这是一种由于任何原因不允许你重写文本标签的对齐方式的样式。

为了解决这个问题,你可以在同一个位置制作一个简单的UITableViewCell子类。

0

让单元格的样式改变为default

let cell = UITableViewCell(style: .default, reuseIdentifier: cellId) 

我创建的故事板字幕细胞,我意识到了textLabel的尺寸是适合其内容。所以你不能对齐textLabel的文字。但是你可以用基本的单元格来完成,它的大小与单元格相匹配。

enter image description here