views:

37

answers:

2

I'm using the CAGradientLayer method from this answer to set a gradient on my UITableViewCells.

However, for this table, I increased the height of the cells via tableView:heightForRowAtIndexPath:. My gradient layer now does not cover the full height of cell, but instead stops at the original height (see pic).

I tried setting the frame of the layer to the cell bounds in tableView:cellForRowAtIndexPath: but that didn't work either. Is there some way to specify the layer should be autoresized?

Thanks!

Code:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        CAGradientLayer *gradient = [CAGradientLayer layer];
        gradient.colors = [NSArray arrayWithObjects:
                           (id)[[UIColor purpleColor] CGColor],
                           (id)[[UIColor redColor] CGColor],
                           nil];
        [cell.layer insertSublayer:gradient atIndex:0];
    }
    cell.layer.borderWidth = 1.0;
    CALayer* gradientLayer = [cell.layer.sublayers objectAtIndex:0];
    DebugLog(@"cell bounds: %@", NSStringFromCGRect(cell.bounds));
    gradientLayer.frame = cell.bounds;

    // Configure the cell...
    return cell;
}
A: 

Please post your code from cellForRowAtIndexPath and heightForRowAtIndexPath.

MrZoidberg
alright.. posted the code, and a pic of what's happening. would appreciate some pointers here, as other must be doing something like in their apps :D
initlaunch