的UITableView单元格背景就像在“音乐”应用
问题描述:
可能重复:
Setting background color of a table view cell on iPhone
how to change the color alternate cell on table view的UITableView单元格背景就像在“音乐”应用
我想有正常的背景和下一个与有些大背景下一个单元格像这个屏幕截图: 任何想法如何实现这个很好,干净的无限数量的单元格? 在此先感谢!
答
FizzBuzz:
-(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;
}
+0
这种方法没有问题,除非在单元中有任何编辑附件。此代码我尝试过'[cell.accessoryView setBackgroundColor:[UIColor colorWithRed:243.0f/255.0f green:243.0f/255.0f blue:243.0f/255.0f alpha:1.0f]];'不起作用 – 2012-07-19 09:07:08
这是一个 “伟大” 的背景下...你尝试过什么?这些如何:http://stackoverflow.com/questions/10213364/how-to-change-the-backgroundcolor-for-all-uitableviewcells http://stackoverflow.com/questions/900094/setting-background-color-of -a-table-view-cell-on-iphone?lq = 1 http://stackoverflow.com/questions/281515/how-to-customize-the-background-color-of-a-uitableviewcell第二个很漂亮更确切地说你的问题。实际上,这基本上是重复的。 – 2012-07-18 19:03:46