Reputation: 19
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)
Upvotes: 1
Views: 149
Reputation: 19
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
Upvotes: 0
Reputation: 20379
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;
Upvotes: 1
Reputation: 6114
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.
Upvotes: 0