A method to change the background color and background image of UITableView in IOS applications _ios

Source: Internet
Author: User

Change the header, footer background color of the UITableView

It is a common problem to change the header and footer background color of the UITableView. The general practice previously known is to implement Tableview:viewforheaderinsection: return a custom view where nothing is filled in and only the background color is set. But today, a more concise approach is found:

For iOS 6 and beyond, implement this new delegate function:

Copy Code code as follows:

-(void) TableView: (UITableView *) TableView Willdisplayfooterview: (UIView *) View forsection: (nsinteger) Section {
View.tintcolor = [Uicolor Clearcolor];
}

You can also change the color of the text:
Copy Code code as follows:

-(void) TableView: (UITableView *) TableView Willdisplayfooterview: (UIView *) View forsection: (nsinteger) Section
{
Uitableviewheaderfooterview *footer = (Uitableviewheaderfooterview *) view;
[Footer.textlabel Settextcolor:[uicolor Whitecolor]];
}

Modify the background picture of TableView

Modify the background picture of UITableView

1. The picture is shown as ' patternimage ' mode.

Copy Code code as follows:

Viewdidload

Self.tableView.backgroundColor = [Uicolor colorwithpatternimage:[uiimage imagenamed:@ "BackgroundImage"]];

Cellforrowatindexpath

Cell.backgroundcolor = [Uicolor Clearcolor];


In this case, the background image is tiled like a floor tile. Pull TableView background image will move, if the number of rows exceeds the height of the background picture, will then display the next picture.

2. The normal background picture.

Copy Code code as follows:

Viewdidload

self.tableview.backgroundcolor= [Uicolor Clearcolor];

Uiimageview*imageview = [[Uiimageview alloc]initwithimage:[uiimageimage named:@ "BackgroundImage"]];

Self.tableView.backgroundView = ImageView;

Cellforrowatindexpath

Cell.backgroundcolor = [Uicolor Clearcolor];


In this case, the background image does not move, that is, no matter how many rows see the same background.

Related Article

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.