Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to change the color alternate cell on table view

Tags:

iphone

I want to display data on table view cell from the database so I want to give the color to cell according to data means for 1st cell gray then next two cells in brown again I want display gray cell, so can anyone tell me what is the simplest procedure for it?

like image 739
Priyanka Avatar asked May 10 '11 05:05

Priyanka


People also ask

How do I change the background color of a table in Swift?

Basic Swift Code for iOS Apps For changing the background color of the table view cell, you should change the contentView. backgroundColor property of the cell. Now run the project to see the effect.

What is Uitableview in Swift?

A view that presents data using rows in a single column. iOS 2.0+ iPadOS 2.0+ Mac Catalyst 13.1+ tvOS 9.0+


1 Answers

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row % 2 == 0) {
        [cell setBackgroundColor:[UIColor whiteColor]];
    }
    else {
        [cell setBackgroundColor:[UIColor lightGrayColor]];
    }
}
like image 184
Mitesh Khatri Avatar answered Nov 15 '22 13:11

Mitesh Khatri