我有一个表视图。因为我想设置第一个单元格的颜色alone..Others应该在white...How中我可以这样做吗
我需要你的帮助...
提前感谢……
发布于 2010-08-26 14:59:44
在cellForRowAtIndexPath中,检查indexPath.row ==是否为0,然后设置自定义背景。否则设置默认背景。
// Customize the appearance of table view cells.
- (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] autorelease];
}
// Configure the cell...
if (indexPath.row == 0) {
//set custom background color
} else {
//set default background color
}
return cell;
}发布于 2011-01-04 19:33:26
您应该在"willDisplayCell“委托方法中进行颜色更改,而不是在"cellForRowAtIndexPath”中创建它时进行更改。否则,当向电池添加例如附件时,它可能不会粘住或可能显示不好。
查看这篇文章以了解更多细节:Setting background color of a table view cell on iPhone
发布于 2013-04-04 16:57:12
if(indexPath.row == 0)
{
UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
bg.backgroundColor = [UIColor colorWithRed:175.0/255.0 green:220.0/255.0 blue:186.0/255.0 alpha:1];
cell.backgroundView = bg;
[bg release];
}https://stackoverflow.com/questions/3572659
复制相似问题