在UITableView的单元格中设置边距可以通过以下几种方式实现:
class CustomTableViewCell: UITableViewCell {
override func layoutSubviews() {
super.layoutSubviews()
contentView.frame = contentView.frame.inset(by: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
}
}
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.contentView.frame = cell.contentView.frame.inset(by: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
}
class CustomTableViewCell: UITableViewCell {
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
let margin: CGFloat = 10
contentView.translatesAutoresizingMaskIntoConstraints = false
contentView.leadingAnchor.constraint(equalTo: leadingAnchor, constant: margin).isActive = true
contentView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -margin).isActive = true
contentView.topAnchor.constraint(equalTo: topAnchor, constant: margin).isActive = true
contentView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -margin).isActive = true
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
以上是在UITableView的单元格中设置边距的几种方法。根据具体的需求和使用场景,选择适合的方法来实现边距的设置。
腾讯云相关产品和产品介绍链接地址:
或 | 元素组成表格结构;其中: |
---|---|
元素定义表头, | 元素定义表格单元。
为了让表格更美观,我们会用到:border,colspan,rowspan,align,bgcolor 等来美化表格,具体在本文都有讲解; 02 扫码添加站长 进交流群 领取专属 10元无门槛券 手把手带您无忧上云 相关资讯活动推荐 |