mardi 23 juin 2015

Can't determine width of table view cell

Oddly enough, I cannot seem to figure out why I can't return the width of the table view cell in this code. This is located in my custom UITableViewCell. My goal is to create a gradient that extends the width of the cell so certain text can be readable and not be obscured by a picture lying underneath. The gradient appears but seems to extend about 9/10 to the edge of the screen. I thought it may have something to do with an accessory view although i set it to none. After several adjustments, I can't figure out why it's not extending the width of the cell. I don't want to hard code a value to be lazy, just looking to understand why this is occurring in hopes to avoid it in the future. Thanks!

//Adds Gradient to the information background to allow text to be readable
func addGradientForInformationBackground(){
    InformationBackground.backgroundColor = UIColor.clearColor();
    let gradient = CAGradientLayer();

    gradientFrame = self.frame;

    //build the colors array for the gradient
    var colors = NSArray(array:[UIColor.clearColor().CGColor,UIColor.blackColor().colorWithAlphaComponent(0.3).CGColor,UIColor.blackColor().colorWithAlphaComponent(0.5).CGColor,UIColor.blackColor().colorWithAlphaComponent(0.6).CGColor,UIColor.blackColor().colorWithAlphaComponent(0.7).CGColor,UIColor.blackColor().colorWithAlphaComponent(0.9).CGColor,UIColor.blackColor().CGColor]);

    //apply the colors and the gradient to the view
    gradient.colors = colors as [AnyObject];

    self.InformationBackground.layer.insertSublayer(gradient, atIndex: 0);

See more ..

Aucun commentaire:

Enregistrer un commentaire