Workaround for child view background transparency when IOS UITableViewCell clicked

Source: Internet
Author: User

UITableView controls are widely used in the development of iOS projects. When you do a custom UITableViewCell, you often encounter the problem of adding a sub-view with a background color on UITableViewCell, and when the user taps UITableViewCell or selects UITableViewCell, The child view on the cell has been strangely changed, its background color is transparent, and if the child view added to the cell is just a color block, then we look like this sub-view is somehow gone.
if set self.selectionstyle = Uitableviewcellselectionstylenone; This can also solve the problem.
But if you want to click on the cell to have a background color, the above method is useless.         (Provides a way to set the background of the cell Self.selectedbackgroundview = [[UIView alloc] initWithFrame:self.frame]; Self.selectedBackgroundView.backgroundColor = [Uicolor Redcolor]), this time we only need to rewrite the cell's two parent class two methods, re-set the background color of the child view.

// This method is called when the cell is selected or unchecked-(void) setselected: (BOOL) selected animated: (bool) animated {    [ Super setselected:selected animated:animated];     = [Uicolor bluecolor];} // This method is called when the user presses and holds the cell -(void) sethighlighted: (BOOL) highlighted animated: (BOOL) animated{    [ Super sethighlighted:highlighted animated:animated];     = [Uicolor bluecolor];}

Workaround for child view background transparency when IOS UITableViewCell clicked

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.