UITableView Cell背景,如'Music'应用程序

Ser*_*yov 0 iphone xcode objective-c uitableview ios

可能重复:
在iPhone上设置表格视图单元格的背景颜色如何更改表格视图上
的颜色备用单元格

我希望有一个正常背景的单元格和下一个具有相似背景的单元格,如此截图: 在此输入图像描述 关于如何为无限数量的单元格实现这个漂亮和干净的任何想法?提前致谢!

Cod*_*aFi 6

FizzBu​​zz:

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    if ((indexPath.row % 2) == 0) {
        [cell.contentView setBackgroundColor:[UIColor whiteColor]];
        [cell.textLabel setBackgroundColor:[UIColor whiteColor]];
    }
    else {
        [cell.contentView setBackgroundColor:[UIColor colorWithRed:243.0f/255.0f green:243.0f/255.0f blue:243.0f/255.0f alpha:1.0f]];
        [cell.textLabel setBackgroundColor:[UIColor colorWithRed:243.0f/255.0f green:243.0f/255.0f blue:243.0f/255.0f alpha:1.0f]];
    }
    cell.textLabel.text = [songArray objectAtIndex:indexPath.row];
    return cell;
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


归档时间:

查看次数:

412 次

最近记录:

13 年,6 月 前