Reputation: 10329
I have a problem with a line between cell which just doesn't want to go away.
I have tried the following
.None
in both code and Interface Builder.CGRect
for contentView
by 1px.clipToBounds
to true
for header, footer and cell.Whatever I do, I can't seem to ger rid of the lines in between:
Initiation of my 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
}
}
The lobby header cell, (footer and cell are similar):
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()
}
}
}
Upvotes: 0
Views: 1261
Reputation: 1915
Your cell views seems to come from a Xib.
UITableViewCell
component in xibs often has a 1 pixel margin at the bottom (between the contentView
and the tableViewCell
itself).
Try to add a subview in the cell.contentView
and make it so the background view height is 1 pixel bigger than the contentView.
Upvotes: 2
Reputation: 974
Try to set up clearColor for separators
tableView.separatorColor = UIColor.clearColor()
Upvotes: 0