在TableView中的两个单元格之间添加填充
使用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
}
created a basic chat application using websocket, and for a proper look I want to give my each cell a little bit padding. But really couldn't figure out how to do that currently tried below solution but it only gives padding "inside my cell" which I want "outside padding"
tried
import 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
}
}
tried
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
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有像uitableview中的单元格之间的空间这样的概念。
最好的选择是将填充物添加到单元本身的内容中。
因此,与其具有具有内容高度80的高度80的单元格。将行高度更改为100,并将内容保持在80的高度。
通过这样做,您现在已经在每个单元格之间创建了一个20的“空间”。
There is no such concept as the space between cells in UITableView.
Your best bet is to add padding to the content of the cell itself.
So, instead of having a cell of height 80 with content height 80. Change the row height to 100 and keep the content at height 80.
By doing that you now have created a “space” of 20 between each cell.