Remove gap between UITableViewCells - ios

I have a UITableView with 10 cells.
I've changed my UITableView's background color to red, but now there is a small red line between each cell (in addition to the separator line).
I need to disable this small gap between the cells that the background color won't be visible between the cells.
Screenshot:
Does anybody know how can I do this?
Thanks!

By going through your snap shot it is clear to me :
there is a separator which is a thin black line with custom offset set. That you can removed as mentioned in one of the answers.
other one is there is a red colour appearing in between cells. Please check is your tableView cell has clearcolor set. As you can see the last cell doesn't have red coloured line in bottom. Which i feel is you have a label over your cell which starts some pixel below the actual cell starts and hence you are able to see red coloured line over all cell excepts bottom of last cell.

In storyBoard select your tableView and then select "Attribute inspector"(at Right side) then Set "Seperator"->"None"
You can also do it by programatically -
UITableView property separatorStyle. Make sure the property is set to UITableViewCellSeparatorStyleNone and you're set.
example -
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

Try this in viewdidload:
self.tableview.backgroundcolor =[UIColor clearColor];
or
self.tableview.backgroundcolor =[UIColor whitecolor];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

Related

UITableViewCell will not work with UIColor colorWithRed [duplicate]

I have created a bunch of cells which I reuse in a table view. All of those cells just have different UILabels inside them and some UIImageViews (nothing covers the complete cell).
Setting the background color in IB has no effect (always white or transparent, can't say which one of them). But if I press Command-R (simulate interface) the cell has the correct background color in the simulator.
I tried to set it in tableView:cellForRowAtIndexPath: but it doesn't work like I would think either.
This does the trick:
cell.contentView.backgroundColor = [UIColor redColor];
but these have no effect (even if I set the cell.contentView.backgroundColor to clearColor):
cell.backgroundView.backgroundColor = [UIColor redColor];
cell.backgroundColor = [UIColor redColor];
I set all the layout/font/background stuff in IB. Any idea why this isn't working in this case?
Why do I need to modify the contentView's backgroundColor and not the backgroundView's?
It seems to be a common issue. Could somebody please point me in the right direction to (finally) understand how background colors are handled within a table view cell.
To change the background color of the cell, you have to do it in the willDisplayCell:forRowAtIndexPath: method. This is mentioned in the UITableViewCell documentation near the bottom of the Overview. So you need:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor redColor];
}
The contentView is just the recommended subview to put custom controls in so that the cell gets layed out properly when table editing is going on.
There's an easier solution: When you create a UITableViewCell in Interface Builder, simply drag and drop an additional UIView so that it covers the entire UITableViewCell you're creating within IB. Place your additional UI elements on top of this additional UIView. You can set this extra UIView to whatever background you like.
There are quite a few answers on StackOverflow that suggest you change the background color of your UITableViewCell by using a line of code like this one:
cell.contentView.backgroundColor = [UIColor redColor];
If you add a drop shadow to your cell by adjusting the contentView's frame size slightly, you may find that this line will change both the background color of your cell and the color of your drop shadow area as well.

When I selected a UITableViewCell and changed the background color the label then top got hidden

I used the original UITableViewCell, and settled the cell.selectedBackgroundView.backgroundColor =[UIColor whiteColor].
When I select the cell, the textlabel was covered which means that only the white was showing.
When I selected another cell, the first textLabel was visible and the new one was covered.
try this and you will get a better understanding of how things are working:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// change the background of your label to some other color here , like black
}
if your label is visible now , then this most probably means somehow your label color is being set to white which shouldn't happen as you're cell color is white as well .
The color of the textLable is always black, it just because the color will be highlighted and make it invisible.

UITableView last row separator is wrong color

I am on iOS 8.
I add a view for the footer to stop empty rows at end of the UITableView with
- (UIView *)tableView:(UITableView *)tableViewIn viewForFooterInSection:(NSInteger)section
I have a custom separator colour for the table using
self.tableView.separatorColor = NAV_FG_COLOUR;
However the last row separator is defaulting back to white.
Any ideas welcome.
Make sure you have set clipsToBounds to YES in your UITableViewCell. Otherwise there could be double _UITableViewCellSeparatorView in your cell. One of those will have wrong color for last cell.
if clipsToBounds is YES already then this white color is the background color of UITableViewCell itself. Because last cell doesn't have separator at all when footer view is set up for the table. However height of contentView of your last cell is still 0.5pt less than height of cell. So that it makes visible background color of the cell itself.
use this to set the separator color
[self.tableView setSeparatorColor:[UIColor redColor]];

How to add a white view under cell in to the UITableView?

I will like add a white view under all cell in to the UITableView, because TableView background is Clear Color, and when Cell N is one or two under these is clear.
Screenshot
I will like under these cells view color will white.
P.D. Sorry, my english is so bad. =(
You mentioned above that there are UIView elements on your UITableView background so setting he background color of it would not work, correct?
You could try setting the background color of the UITableViewCell itself, and add any of your custom views as subviews on the cell.
cell.backgroundColor = [UIColor whiteColor];
Try to set up tableview's footer view, and make it with a white background.

How to keep the background color of UICollectionViewCells from changing when scrolling?

My UICollectionView's cells have a contentview with a background color of white upon loading. Users can change the background color of the cell's contentview to cyan by selecting the cell assuming a boolean value (isSplitting) is set to YES.
My problem arises when I have more cells then fit on the screen and the user has selected cells and thus changed their contentview's background color to cyan.
I have instances where cells that are cyan get scrolled out of view and when scrolled back in are white. I also have instances where cells that are not cyan are scrolled into view and are cyan.
I understand that the cells are being dequeued for reuse and retaining their background colors when getting loaded into a different indexpath.
I have resolved the issues of cells that are not selected becoming cyan upon scrolling into view. I have not however been able to resolve the issue of certain selected cells losing their cyan color when scrolled in and out of view.
Here is the current logic I have in cellForItemAtIndexPath.
if (!isSplitting) {
cell.contentView.backgroundColor = [UIColor whiteColor];
}
else{
for (NSIndexPath *collectionIndexPath in [self.myCollectionView indexPathsForSelectedItems]) {
if (indexPath == collectionIndexPath) {
cell.contentView.backgroundColor = [UIColor cyanColor];
break;
}
else{
cell.contentView.backgroundColor = [UIColor whiteColor];
}
}
}
I know the that correct cells are indeed selected because another operation using the same for loop above produces the desired results. The logic seems to breakdown if I select the first couple items (turn them to cyan), scroll to the right and select the 10th item. When I scroll back to the left the first couple are still cyan but upon scrolling to the right again the 10th is back to white.
Use isEqual: to compare the indexPaths rather than ==
if ([indexPath isEqual:collectionIndexPath]) {

Resources