I have a UITableView and have set multiple selection while editing to true
tableView.allowsMultipleSelectionDuringEditing = true
In the cell configuration (cellForRowAtIndexPath), I do:
cell.selectionStyle = .default
cell.accessoryType = .checkmark
So when tableView is set to editing mode, I get blue checkmark option on the left side. I want to change the default blue color on that accessory. How do I do that?
If you're using storyboard :
Change the tint color here
In your custom UITableViewCell, set cell's tintColor in awakeFromNib() like so,
class CustomCell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
self.tintColor = .red
}
}
Just set the cell tint color whatever you want. It will automatically change the accessory type color.
[cell setTintColor:[UIColor whiteColor]];
Related
enter image description here
a video clip of this UI, how does it look like
Please Help me how can I make one, I tried to build it by UITableView and for cell UIcollectionView it works well but I can't select collection-view Cell by code ( need after select change the cell view background color )
you can change the background color of UICollectionViewCell by overriding the cell property
override var isSelected: Bool {
didSet {
if isSelected {
self.contentView.backgroundColor = UIColor.blue
} else {
self.contentView.backgroundColor = UIColor.green
}
}
}
also since cell are reusable you may see some cells with blue color while scrolling as they are now reused, to avoid this override the method
override func prepareForReuse() {
super.prepareForReuse()
self.contentView.backgroundColor = UIColor.green
}
In my tableView, I have a subView with a background colour of red and anytime I select a cell in the tableview the background colour disappears. I was wondering if there was a way to fix this?
You have to stop tableview cell selection style. Write below code in cellForRowAtIndexPath method.
cell.selectionStyle = .none
For set cell background color on selection.
cell.contentView.backgroundColor = UIColor.red // here you can set your own custom color.
Try below code.
cell.selectionstyle = .none
I have UItablview with custom cell i need to change a label background colour when select this row, but the label colour is repeated when scroll down
You could subclass your Cell like this (and cellForRow then will not be responsible for updating the color, only for setting default color).
class YourTableViewCellClass: UITableViewCell {
#IBOutlet weak var yourLabel: UILabel!
override func setSelected(_ selected: Bool, animated: Bool) {
if(selected) {
self.contentView.backgroundColor = UIColor.red //or what you want as your cell bg color
self.yourLabel.backgroundColor = UIColor.green //or what you want
} else {
self.contentView.backgroundColor = UIColor.white //or what you want as your cell bg color
self.yourLabel.backgroundColor = UIColor.red //or what you want
}
} }
What I understand is, you put code in didSelectRow method of tableview to change the color, but it shows previous color while scrolling.
So,you need to set condition in cellForRow method also e.g.
if(condition)
{
lbl.textcolor = x
}
else
{
lbl.textcolor = y
}
As a UITableView is allowsMultipleSelectionDuringEditing = true,
the default selection style is a light-blue look on a selected cell:
I set the cell contentView.backgroundColor = .whiteColor() when the cell got highlighted/ selected,
consequently make the circle-checkmark area remain light-blue but not the whole cell:
TL;DR
I need the whole cell to be white as it's multiple-selected,
which means I cannot set the cell's selectionStyle = .None.
Is there a way to achieve this?
Have you tried cell.backgroundColor = UIColor.whiteColor() ?
UITableView in multi-selection mode removes background colours of all subviews in selected cell. I want not to change the backgrounds colours of my subviews just show the tick mark on selection. I tried to assign cell's "selectedBackgroundView" and "multipleSelectionBackgroundView" to a transparent view but it didn't work. I also tried to reassign the backgrounds of my subviews in "setEditing" and "setHighlighted" functions of cell but it also didn't work. Is there any other way to fix this issue?
Set the tableView cell Selection to None in the Attributes inspector, or set cell.selectionStyle = .None in code.
for Swift 3
cell.selectionStyle = .gray
cell.selectedBackgroundView = {
let colorView = UIView()
colorView.backgroundColor = UIColor.clear
return colorView
}()