[IOS Dev] Custom (rewrite) UITableViewCell Highlight background color

Source: Internet
Author: User

In the iOS SDK, the highlighted background color for UITableViewCell only supports two colors, uitableviewcellselectionstyleblue and Uitableviewcellselectionstylegray.

So how do you customize this color? One idea is to set the background color of the cell you want when the cell is clicked, and reset the cell back to the original background color when the click is released, so that you can achieve the desired effect.

The following is the implementation-specific code:

-(void) DrawRect: (cgrect) rect  {      if  (self.highlighted) {          = [Uicolor Colorwithhexstring:@ "0x383838"];      } Else {          = [Uicolor clearcolor];      }  }     -(void) sethighlighted: (BOOL) highlighted animated: (BOOL) animated  {      [super Sethighlighted:highlighted animated:animated];      [Self setneedsdisplay];  }  

1. Inheriting UITableViewCell

2. Rewrite the above two methods.

When the user clicks or releases, the system will call the following method to change the cell's highlighted background color.

-(void) sethighlighted: (BOOL) highlighted animated: (BOOL) animated

[IOS Dev] Custom (rewrite) UITableViewCell Highlight background color

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.