使用 websocket 創建了一個基本的聊天應用程式,為了看起來合適,我想給我的每個單元格添加一點填充。但真的無法弄清楚如何做到這一點,目前在下面的解決方案中嘗試過,但它只提供“我的單元格內部”的填充,我想要“外部填充”
試過了
匯入 UIKit
class CellView: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
super.layoutSubviews()
self.backgroundColor = .systemBlue
self.layer.cornerRadius = 10
}
override func layoutSubviews() {
super.layoutSubviews()
contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 8))
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
試過了
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return CGFloat(15.0)
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let v = UIView()
v.backgroundColor = .clear
return v
}
uj5u.com熱心網友回復:
UITableView 中沒有單元格間距這樣的概念。
最好的辦法是為單元格本身的內容添加填充。
因此,不要讓一個高度為 80 的單元格內容高度為 80。將行高更改為 100 并將內容保持在高度 80。
通過這樣做,您現在在每個單元格之間創建了一個 20 的“空間”。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/486951.html