Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Using custom views for the cell background allows you to fully customise the look of the cell, but might not scale well when the screen orientation is changed. Also, if all you need is a gradient background that works in both plain cells and grouped style cells, you might be best off with this...</p> <p>I have another solution, which is far less code and only requires a gradient image. The rounded corners of the group cell style are still drawn by the framework, so we don't need to worry about providing a custom image for the top, middle and bottom cell styles to cater for the rounded corners with this method. This is how it looks:</p> <p><img src="https://i.stack.imgur.com/ZBCLb.png" alt="Image showing the table view cells containing the gradient background in grouped style with rounded corners"></p> <p>The gradient image is a single pixel wide and as high as the cell (which is 44 pixels in this example). </p> <pre><code>cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"cellBackground_1x44.png"]]; </code></pre> <p>The code makes use of the colorWithPatternImage method on UIColor, available since iOS 2.0. This code should be called in <code>tableView:cellForRowAtIndexPath:</code>. It isn't necessary to repeat the call when a cell is re-used, only when the cell is initially created.</p> <p>To go with the grey gradient I am using, I found it useful to set the selection colour for selected cells to match:</p> <pre><code>cell.selectionStyle = UITableViewCellSelectionStyleGray; </code></pre> <p>You might also want to change the colour of the cell borders too, using something like:</p> <pre><code>[self.tableView setSeparatorColor:[UIColor darkGrayColor]]; </code></pre> <p>Well, that's it. I hope people find this useful. I was searching online yesterday for a few hours and only came up with references containing custom drawing code which generated gradients and rounded corners, or I found links to Matt Coneybeare's "HOW TO MAKE CUSTOM DRAWN GRADIENT BACKGROUNDS IN A GROUPED UITABLEVIEW WITH CORE GRAPHICS" blog post. All work fine, but if you just want something simple I believe this is it.</p>
    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.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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