In my app i am using one table.Now i want to separate two rows by alternate colors.That means my first row will have white color,my second row will have gray color third will have again white color likewise...So please anyone have solution for it.Then please share it.Thanks in advance.
Akshay
Here is a relatively simple implementation:
In your tableViewController
implement the cellForRow
with something like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"DefaultCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// check if row is odd or even and set color accordingly
if (indexPath.row % 2) {
cell.backgroundColor = [UIColor whiteColor];
}else {
cell.backgroundColor = [UIColor lightGrayColor];
}
return cell;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With