Toggled switch overlaps table view cells
gregbarbosa opened this issue · comments
Thanks for putting paper-switch together! I immediately found uses for it and started putting it to work.
Not sure if it's expected or not, but I noticed when placing the switch into a table view's cell, the color bounds goes past the bounds of views inside the cell or even the cell's bounds itself. Could it be that I'm doing something wrong here?
Hello gregbarbosa! This issue is caused by hierarchy of views in UITableViewCell(or it's descendant). UITableViewCell has contentView
subview which has cell's content as subviews. RAMPaperSwitch set masksToBounds
in true for layer of own superview. But in this case we have to set this property also for cell's layer, which is superview of superview because of intermediate view - contentView
.
All you need to fix it is set cell layer property masksToBounds
in true.
For example:
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier(kTableViewCellIdentifier, forIndexPath: indexPath) as TableViewCell
cell.layer.masksToBounds = true
return cell;
}
I hope this helps You.
Thanks for your issue.
@ooleynich thanks so much for the help. Understanding that helped me get my head around it all and what I was missing.
Applying cell.layer.masksToBounds = true
fixed the problem of it running outside the cell's content view's bounds.
I've only have one other problem where my UITableViewCell is a custom cell that has the masksToBounds set to false because of a card style I'm applying to it.
func cardSetup() -> Void {
cardView.alpha = 1.0
cardView.layer.masksToBounds = false
cardView.layer.cornerRadius = 2.0
cardView.layer.shadowColor = UIColor(white: 0.0, alpha: 0.35).CGColor!
cardView.layer.shadowOffset = CGSizeMake(0.0, 1.0)
cardView.layer.shadowRadius = 1.5
var path = UIBezierPath(rect: cardView.bounds)
cardView.layer.shadowPath = path.CGPath
cardView.layer.shadowOpacity = 0.75
}
This causes some weirdness on the tableview with RAMPaperSwitch applied, but it works better than before. I'll play around with it some more.
I'm glad you were able to get this working, I'm closing the issue.