Mohit Arya
Mohit Arya

Reputation: 19

Custom Tableview cell width issue

After changing the opacityIB Screen ShotI'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)

enter image description here

Upvotes: 1

Views: 149

Answers (3)

Mohit Arya
Mohit Arya

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

Sandeep Bhandari
Sandeep Bhandari

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,

enter image description here

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

Yury
Yury

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

Related Questions