UITableViewCell clear spacings - ios

I've got an UITableView with clear background color. The cells are made of:
bckgrndView - slightly bigger to get spacing betweens cells
-> contentView - contains content, set green
-> -> label, textview - green too
I set everything in interface builder (backgroundColor -> clear, opaque -> no), expect that i have to repeat
cell.backgroundColor = [UIColor clearColor];
cell.opaque = NO;
cell.backgroundView = nil;
in cellForRowAtIndexPath or else, background would be white (bug?)
But as soon as i scroll the clear color is gone and the spacing gets green(== same color as textview)
What am I missing?

Fixed it!
Renaming the inner view differently from "contentView" did it.
UITableView has a own property named "contentView", so there was the conflict...

Related

Custom Tableview cell width issue

I'm changing the background colour of the labels dynamically, the width of the cell seems to be static and is working properly in case of 6s only, the background colour fades if the size of the display increases
cell.container.layer.backgroundColor = GetColor().randomColor(indexPath.row).colorWithAlphaComponent(0.5).CGColor
cell.title.layer.backgroundColor = GetColor().randomColor(indexPath.row).colorWithAlphaComponent(0.8).CGColor
New Code// after changing the opacity
// cell.container.layer.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.85).CGColor
cell.title.backgroundColor = GetColor().randomColor(indexPath.row).colorWithAlphaComponent(0.5)
Mohit Arya,
I beilieve you have applied Autolayout constraint on the label inside the cell :) If yes please verify if its the same as I have shown below if not please add autolayout constraints properly,
As you are setting the color of the label itself and want it to cover the whole cell setting all the four constraint to 0 is necessary
EDIT:
Now as per your comment, if constraints are same as I have given below your label must be covering the whole cell :)
Then all you have to do is to
[cell.label setBackgroundColor: GetColor().randomColor(indexPath.row).colorWithAlphaComponent(1.0)]
cell.label.opaque = YES;
Check background color (and background color alpha value) for all views in your cell view hierarchy. For example, issue like this can appear if your cell's contentView have background color with alpha < 1, and your label (which size don't fit contentView) have same background color. Thats all what we can say by information you provided.
So, use different colors, or use alpha = 1, or use clear color in label.
I found the solution..the following code was interfering with the UI, I still don't know why the container.bounds is not returning the actual width
container.layer.shadowColor = UIColor.lightGrayColor().CGColor
container.layer.shadowOpacity = 1
container.layer.shadowOffset = CGSizeMake(0, 1);
container.layer.shadowRadius = 2
container.layer.shadowPath = UIBezierPath(rect: container.bounds).CGPath

Remove gap between UITableViewCells

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];

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.

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.

UICollectionViewCell pixel artifacts

I have a custom UICollectionViewCell, I have few views in its contentView.
I have an UIImageView with image (1 pixel colored) and I use it to fill my view.
I also cut the corners like this -
self.myBackground.layer.cornerRadius = 8.0;
self.myBackground.layer.masksToBounds = YES;
Color of my view and all collectionViewCells and their contentViews is [UIColor whiteColor]
But I am getting weird grey line below it. I am not setting it anywhere and I don't need it.
How can I remove it?
I have found the answer, it is separator. After setting separator view to nil it disappeared.

Resources