Reputation: 5101
I am creating a table view with custom cells.
Every cell has three buttons on it. I have added a view that should occupied the width and height from the cell, overlapping the three buttons. I am using it to create a swipeable cell.
The view that serves as overlay has white color background and opaque, but testing the app on the simulator, I have detected that when tapping on the cell, the buttons are lightly shown, please take a look at the picture.
What should I do to avoid the buttons to be seen. Why does it happen now if the overlay view is set as opaque. A second issue is when tapping on the cell, the left red bar, also a view, dissapear...
Thank you.
Upvotes: 0
Views: 87
Reputation: 14351
The above answer will turn off cell selection highlighting completely and that may not be what you want.
After testing this out several times it appears what's happening is that when a cell is selected, iOS will convert the background color for all views on that cell to clearColor.
So the work around is to simply set the color of your on-cell views back to normal on selection:
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(tableView.indexPathForSelectedRow()!) as! MyCell
cell.MyViewOnMyCell.backgroundColor = UIColor.redColor()
}
See this question for other answers.
Upvotes: 0
Reputation: 1538
I believe this is a result of UITableViewCell
's default selection styles. Let's try removing the default style and customizing it.
Try setting (depending on your implementation):
cell.selectionStyle = UITableViewCellSelectionStyleNone;
inside cellForRowAtIndexPath
orself.selectionStyle = UITableViewCellSelectionStyleNone;
in the Cell's custom subclass orThen, you can implement a custom selection style inside the UITableViewCell's custom class. Inside your initialization method, add something like:
self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.bounds]; self.selectedBackgroundView.backgroundColor = [UIColor lightGrayColor];
Upvotes: 1