Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggled switch overlaps table view cells #1

Closed
gregbarbosa opened this issue Dec 3, 2014 · 3 comments
Closed

Toggled switch overlaps table view cells #1

gregbarbosa opened this issue Dec 3, 2014 · 3 comments

Comments

@gregbarbosa
Copy link

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?

Screenshot

@ooleynich
Copy link
Contributor

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.

@gregbarbosa
Copy link
Author

@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.

Screenshot

@Juriv
Copy link
Contributor

Juriv commented Dec 5, 2014

I'm glad you were able to get this working, I'm closing the issue.

@Juriv Juriv closed this as completed Dec 5, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants