Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I struggled for days with this. The solution ended up being quite simple but the various parts of the puzzle were spread across several different answers and sites. The missing piece of the puzzle turned out to be the distinction between the content view and the background view and where the selection color is applied.</p> <p>Features of my solution:</p> <ul> <li>I load my cell from a nib so that I can layout the content in IB. Feel free to lay out the content programmatically.</li> <li>I grab the gradient colors from a global style object because I need to customize the gradient by client. <ul> <li>I set the selection color of the cell to gray in the nib so the default (blue) does not clash with my color scheme.</li> </ul></li> <li>I add the gradients to the background view. If you don't do this, the selection color does not show correctly. UITableViewCell does not have a background view by default so you have to create it first.</li> </ul> <p>This last point was the secret ingredient that made it all work for me.</p> <p>I added a factory method to my UITableCellView subclass because I wanted to use the same cell in multiple tables.</p> <pre><code>+(ActivityDetailCellView *) createWithStyle: (WMStyle *) style { UIViewController *temporaryController = [[UIViewController alloc] initWithNibName: @"ActivityDetailCellView" bundle: nil]; ActivityDetailCellView *cell = (ActivityDetailCellView *) temporaryController.view; CAGradientLayer *lightGradient = [CAGradientLayer layer]; lightGradient.frame = cell.bounds; lightGradient.colors = style.lightGradient; UIView *background = [[UIView alloc] initWithFrame: cell.bounds]; [background.layer insertSublayer:lightGradient atIndex:0]; cell.backgroundView = background; return cell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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