我对单元格之间的线条有疑问,它不想消失。
我试过以下方法
- 在代码和 Interface Builder 中将分隔符样式设置为
.None
。 - 将
contentView
的框架CGRect
的大小增加 1px。
页眉、页脚和单元格的 clipToBounds
为true
。
启动我的 TableView:
@IBOutlet weak var tableView: UITableView! {
didSet {
tableView.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0)
tableView.clipsToBounds = true
tableView.separatorInset = UIEdgeInsetsZero
tableView.separatorStyle = .None
if let nib = NSBundle.mainBundle().loadNibNamed(LobbySliderHeaderCollectionReusableView.classIdentifier, owner: self, options: nil).first as? LobbySliderHeaderCollectionReusableView {
tableView.tableHeaderView = nib
}
}
}
...
extension LobbyViewController: UITableViewDataSource {
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return categoryChunks.count
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cellType: GameCollectionCellType!
if let type = cellTypes[indexPath.item] {
cellType = type
} else {
var isNot: GameCollectionCellType? = nil
if let lastType = cellTypes[indexPath.item] {
isNot = lastType
}
cellType = GameCollectionCellType.randomItem(isNot)
cellTypes[indexPath.item] = cellType
}
let chunk = categoryChunks[indexPath.section][indexPath.row]
let cell = tableView.dequeueReusableCellWithIdentifier(GameCollectionViewCell.classIdentifier, forIndexPath: indexPath) as! GameCollectionViewCell
cell.configureWithGames(chunk)
let color = waveColors[indexPath.section % 2]
cell.fillColor = color
cell.clipsToBounds = true
return cell
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let lh = tableView.dequeueReusableCellWithIdentifier(LobbyHeader.classIdentifier) as! LobbyHeader
lh.fillColor = waveColors[section % 2]
lh.contentView.clipsToBounds = true
if categories.count > 0 {
let cat = categories[section]
lh.title.text = cat.name
lh.showMore.setTitle("%@ items".localizedStringWithParameters(["\(cat.games.count)"]), forState: .Normal)
lh.tag = section
} else {
lh.title.text = ""
}
lh.sizeToFit()
return lh
}
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let lf = tableView.dequeueReusableCellWithIdentifier(LobbyFooter.classIdentifier) as! LobbyFooter
let i = section % 2 == 0 ? 1 : 0
let color = waveColors[i]
lf.waveView.fillColor = color
lf.waveView.clipsToBounds = true
lf.contentView.clipsToBounds = true
let bgColor = waveColors[section%2]
lf.contentView.backgroundColor = bgColor
return lf
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 30
}
func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 10
}
}
大厅标题单元格(页脚和单元格类似):
class LobbyHeader: UITableViewCell {
@IBOutlet weak var title: UILabel!
@IBOutlet weak var showMore: UIButton!
var fillColor: UIColor = UIColor.clearColor() {
didSet {
contentView.backgroundColor = fillColor
}
}
var showGames: (()->())?
class func nibForView() -> UINib {
return UINib(nibName: classIdentifier, bundle: nil)
}
override func prepareForReuse() {
super.prepareForReuse()
title.text = ""
showMore.setTitle("", forState: .Normal)
}
override func awakeFromNib() {
super.awakeFromNib()
backgroundColor = BackgroundColors.defaultBackgroundColor
}
@IBAction func showMoreAction(sender: UIButton) {
if let showGames = showGames {
showGames()
}
}
}
最佳答案
您的单元格 View 似乎来自 Xib。
xibs 中的 UITableViewCell
组件通常在底部有 1 个像素的边距(在 contentView
和 tableViewCell
本身之间)。
尝试在 cell.contentView
中添加一个 subview ,使背景 View 的高度比 contentView 大 1 个像素。
关于ios - 删除 UITableView 中页眉/页脚/单元格之间的分隔,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35508203/