Color settings when selecting UITableViewCell for iOS development

Source: Internet
Author: User

1. default color settings

 
 
  1. // Colorless
  2. Cell. selectionStyle = UITableViewCellSelectionStyleNone;
  3.  
  4. // Blue
  5. Cell. selectionStyle = UITableViewCellSelectionStyleBlue;
  6.  
  7. // Gray
  8. Cell. selectionStyle = UITableViewCellSelectionStyleGray;

2. Custom color and background settings

Change the background color when UITableViewCell is selected:

 
 
  1. UIColor * color = [[UIColoralloc] initWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 1]; // you can use RGB to define your own color.
  2. Cell. selectedBackgroundView = [[[UIView alloc] initWithFrame: cell. frame] autorelease];
  3. Cell. selectedBackgroundView. backgroundColor = [UIColor xxxxxx];

3. Custom background when UITableViewCell is selected

 
 
  1. Cell. selectedBackgroundView = [[[UIImageView alloc] initWithImage: [UIImage imageNamed: @ "cellart.png"] autorelease];
  2. Font color
  3. Cell. textLabel. highlightedTextColor = [UIColor xxxcolor]; [cell. textLabel setTextColor: color]

4. Set the color of the split line between tableviewcells.

 
 
  1. [theTableView setSeparatorColor:[UIColor xxxx ]]; 

5. Set the font color in the cell.

Prettyprint code

 
 
  1. <span style="color: #888888;" class="com">// Customize the appearance of table view cells.</span><span style="color: #000000;" class="pun">-</span><span style="color: #000000;" class="pun">(</span><span style="color: #000088;" class="typ">UITableViewCell</span><span style="color: #000000;" class="pun">*)</span><span style="color: #000000;" class="pln">tableView</span><span style="color: #000000;" class="pun">:(</span><span style="color: #000088;" class="typ">UITableView</span><span style="color: #000000;" class="pun">*)</span><span style="color: #000000;" class="pln">tableView cellForRowAtIndexPath</span><span style="color: #000000;" class="pun">:(</span><span style="color: #000088;" class="typ">NSIndexPath</span><span style="color: #000000;" class="pun">*)</span><span style="color: #000000;" class="pln">indexPath 
  2. </span><span style="color: #000000;" class="pun">{</span><span style="color: #000000;" class="pln"> 
  3.   </span><span style="color: #880000;" class="kwd">if</span><span style="color: #000000;" class="pun">(</span><span style="color: #006666;" class="lit">0</span><span style="color: #000000;" class="pun">==</span><span style="color: #000000;" class="pln"> indexPath</span><span style="color: #000000;" class="pun">.</span><span style="color: #000000;" class="pln">row</span><span style="color: #000000;" class="pun">)</span><span style="color: #000000;" class="pln"> 
  4.   </span><span style="color: #000000;" class="pun">{</span><span style="color: #000000;" class="pln"> 
  5.     cell</span><span style="color: #000000;" class="pun">.</span><span style="color: #000000;" class="pln">textLabel</span><span style="color: #000000;" class="pun">.</span><span style="color: #000000;" class="pln">textColor </span><span style="color: #000000;" class="pun">=</span><span style="color: #000000;" class="pun">...;</span><span style="color: #000000;" class="pln"> 
  6.     cell</span><span style="color: #000000;" class="pun">.</span><span style="color: #000000;" class="pln">textLabel</span><span style="color: #000000;" class="pun">.</span><span style="color: #000000;" class="pln">highlightedTextColor </span><span style="color: #000000;" class="pun">=</span><span style="color: #000000;" class="pun">...;</span><span style="color: #000000;" class="pln"> 
  7.   </span><span style="color: #000000;" class="pun">}</span><span style="color: #000000;" class="pln"> 
  8.   </span><span style="color: #000000;" class="pun">...</span><span style="color: #000000;" class="pun">}</span> 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.