如何在swift 3中将Tableviewcell显示为气泡?

Jat*_*123 1 uitextview ios swift3

我知道有些库可以为我做,但我不想使用任何库并手动完成.可能吗?

Dáv*_*tor 5

这实际上比看起来更容易,你只需要cornerRadius为你的单元格主视图设置一个并设置clipsToBounds为true.对于左/右对齐,您可以使用具有固定约束的两个不同原型,也可以Autolayout constraints基于单元格以编程方式修改.

对于舍入,请参阅下面使用基本的代码UITableViewCell(您很可能使用自己的子类,但原理是相同的):

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "myCell", for: indexPath)
    cell.backgroundView?.layer.cornerRadius = 5 //set this to whatever constant you need
    cell.backgroundView?.clipsToBounds = true
    return cell
}
Run Code Online (Sandbox Code Playgroud)