Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableViewCell gradient layer auto resize
    primarykey
    data
    text
    <p>I'm using the CAGradientLayer method from this <a href="https://stackoverflow.com/questions/422066/gradients-on-uiview-and-uilabels-on-iphone/1931498#1931498">answer</a> to set a gradient on my UITableViewCells. </p> <p>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 <a href="https://imgur.com/fkyiE.png" rel="nofollow noreferrer">pic</a>).</p> <p>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?</p> <p>Thanks!</p> <p>Code:</p> <pre><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; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload