UITableView
# 取消Header悬停
自定义Section Header
头部UIView
public class MASectionNoHoverHeaderView: UIView
{
weak var tableView:UITableView?
var section:Int = 0
public override var frame: CGRect {
didSet {
if let tableView = tableView {
super.frame = tableView.rectForHeader(inSection: section)
}
}
}
}
# Section分组圆角和设置下划线
设置tableView的两个参数,才能设置separator
tableView.separatorInset = .zero
tableView.layoutMargins = .zero
继承UITableViewCell
,设置cell
左右间距
public class MAAutoWidthCell:UITableViewCell{
public override var frame: CGRect{
didSet{
var newFrame = frame
newFrame.origin.x = 16
newFrame.size.width = UIScreen.width - 32
super.frame = newFrame
}
}
}
通过UITableViewDelegate
,设置圆角,和设置下划线缩进
public func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let count = self.tableView(tableView, numberOfRowsInSection: indexPath.section)
cell.layer.cornerRadius = 8
cell.clipsToBounds = true
cell.layer.maskedCorners = []
if indexPath.row == 0 {
cell.layer.maskedCorners.update(with: [.layerMinXMinYCorner, .layerMaxXMinYCorner])
}
cell.separatorInset = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 0)
if indexPath.row == count - 1 {
cell.layer.maskedCorners.update(with: [.layerMinXMaxYCorner, .layerMaxXMaxYCorner])
cell.separatorInset = UIEdgeInsets(top: 0, left: cell.frame.width, bottom: 0, right: 0)
}
}
上次更新: 2025/03/22, 03:52:10