I am having issues setting the cell background colour on a grouped table cell when in edit mode. It seems to get the checkmark to appear a selection style has to be set and the only options are UITableViewCellSelectionStyleBlue or UITableViewCellSelectionStyleGray.
What I am after is the for the checkmark just to be selected and the cell remain white when it is checked.
You would have thought UITableViewCellSelectionStyleNone would have this behaviour but this stops the checkmark for showing.
I have tried to use setSelectedBackgroundView. This would work if the cell style was not grouped but as it is the round corners do not get drawn.
The properties for the cell above are
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.backgroundView = [self tableViewCellRowBackground];
Where tableViewCellRowBackground is a UIView with orange background.
The editMode is the built in iOS table edit mode with the following properties set on the table
self.tblFiles.allowsSelectionDuringEditing=YES;
self.tblFiles.allowsMultipleSelectionDuringEditing = YES;
Any ideas?
cell.backgroundView = [self tableViewCellRowBackground];
This method is setting an image for your selected cell.You should check out this one to make the selection Style image nil.
In the end I had to create my own custom cells by overriding the drawrect method.
Related
I'm writing a small application to teach myself new design and information retrieval tricks. I'm using the following line to set the background of my UITableViewCell subclass:
cell.contentView.backgroundColor = [UIColor blackColor];
... but it doesn't seem to want to get behind that accessory view:
How do I get the backgroundColor to actually span the entire background of the UITableViewCell?
The accessory view is not added to the cell's contentView. As you can see, the content view is resized by shrinking from the right so the accessory can fit in. This also happens when the delete button is shown.
You need to set the backgroundColor of the whole cell - furthermore, this has to be done in the tableView:willDisplayCell:forRowAtIndexPath:
delegate method.
If you want to set color of entire cell, then use -
cell.backgroundColor = [UIColor blackColor];
Not exactly a definitive answer to this question, but it works well when you use the "grouped" view instead of the standard UITableView style.
I have a cell where the accessory type is set to a disclosure indicator via:
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
Now when selected, it turns white as per default.
Because I have changed the default selection style/view via the cell's 'backgroundView' and 'selectedBackgroundView' properties, I want the disclosure indicator to stay gray as it will look better.
Is there an easy way to do this without having to create a custom disclosure indicator image and adding this to the cell?
Try this link:Custom colored disclosure indicators
I would subclass UITableViewCell and override -setHighlighted:animated: and -setSelected:animated. In these methods, you set the accessoryType to UITableViewCellAccessoryNone. From here all you need to do is add a gray disclosure indicator to your selectedBackgroundView.
Is anyone else experiencing this problem where if you programmatically set the selected state of a UITableViewCell to YES, it colors the text label black?
[cell setSelected:YES]
I can't seem to figure this out. I would expect it to highlight the cell blue. Manually selecting the cell works as it colors the cell blue while the text is displayed in white.
Any help is appreciated. Thanks in advance!
I was having the same problem and fixed it by moving the cell.selected = YES into tableView:willDisplayCell:forRowAtIndexPath instead.
I think it might be related to the note at the bottom of the UITableViewCell docs about changes to background color requiring use of tableView:willDisplayCell:forRowAtIndexPath (presumably selected sets the background color).
I have a tableView populated with custom tableViewCells. The cells are not subclasses, they are merely tableViewCells which have had a lot of tweaking and "subview-adding"(done in the cellForRowAtIndexPath method). The problem occurs when i tap the edit button. Have a look:
PICTURE_1
I know the "delete badge" is hovering above the text, I'll fix that later. My problem is that the "delete badge" and the reorderControl assumes the color of the table's backgroundColor(which I've set to be the same as the top row). I've tried doing this:
cell.accessoryView.backgroundColor = [UIColor clearColor] But it doesn't help which I assume is because the "delete badge" and reorderControl are not displayed in the accesoryView. My problem does not only count for the badge and the reorder control. It also counts for the delete button that appears when I press the delete-badge.
So do anybody know how to fix this? I'm really stuck here.
Thanks.
Looks like you need to assign a background view to your cells, and give that a background color:
cell.backgroundView = [[[UIView alloc] initWithFrame: cell.bounds] autorelease];
cell.backgroundView.backgroundColor = [UIColor gray];
I have a custom UITableViewCell subclass. I have set the contentView of my cell subclass to
a custom UIView class in which i am overriding -drawRect: and doing all of the drawing there.
Also, I am setting cell.contentView.opaque = NO in order to achieve transparency in certain areas of the cell (unfortunately, a backgroud image behind the table must show thru each cell in certain parts to achieve a stylistic effect. i know this is a performance hit. it must be so).
Problem: I still see the default pretty blue gradient background being drawn behind my cell (in the transparent areas) when it is selected or highlighted (being pressed). This is obscuring the image behind the table, which is bad.
Goal: To prevent the blue gradient background from appearing, but still be able to inspect the cell.isSelected and cell.isHighlighted properties from within -[MyContentView drawRect:] to determine how to draw my own custom selection/highlighting.
What I've tried:
setting cell.selectionStyle = UITableViewCellSelectionStyleNone has the desired effect of preventing the pretty blue gradient selection background, but also prevents the cell.isSelected and cell.isHighlighted properties from being properly set, which means i cannot do my own custom selection/highlight drawing
setting cell.selectionBackgroundView = nil and cell.backgroundView = nil in the cell's -init or -prepareForReuse method does not prevent the blue gradient selection background
setting cell.selectionBackgroundView = nil in the -[MyContentView -drawRect:] method does have the desired effect of preventing the blue gradient selection background, but that seems very janky
overriding -[UITableViewCell setSelected:animated:] to be a no-op. this does not have the desired effect of preventing the blue gradient selection background
You must also override setHighlighted: to prevent the blue gradient from ever showing. If you just override setHighlighted: then you end up with a momentary selection effect.
so you'll have these two methods:
- (void)setHighlighted: (BOOL)highlighted animated: (BOOL)animated
{
// don't highlight
}
- (void)setSelected: (BOOL)selected animated: (BOOL)animated
{
// don't select
//[super setSelected:selected animated:animated];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
An excellent resource on customizing UITableViews has been this post by Matt Gallagher. What you'll want to do is set the selectedBackgroundView to a new view (instead of nil) that is either transparent or a UIImageView.
By far the easier method - in my opinion - to achieve this, is by setting the Table View attributes checkbox in the Interface Builder screen where it says "Show Selection on Touch". See the screenshot below:
What has worked for me in the past is just putting:
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { }
In my UITableViewCell subclasses (because it won't call super and make itself highlighted).
Hope this is what you were looking for.
How about this?
// disable user interaction
cell.userInteractionEnabled = NO;