首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在iphone的表视图中设置单个单元格的背景色

如何在iphone的表视图中设置单个单元格的背景色
EN

Stack Overflow用户
提问于 2010-08-26 14:47:39
回答 3查看 574关注 0票数 0

我有一个表视图。因为我想设置第一个单元格的颜色alone..Others应该在white...How中我可以这样做吗

我需要你的帮助...

提前感谢……

EN

回答 3

Stack Overflow用户

发布于 2010-08-26 14:59:44

在cellForRowAtIndexPath中,检查indexPath.row ==是否为0,然后设置自定义背景。否则设置默认背景。

代码语言:javascript
运行
复制
// 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;
}
票数 2
EN

Stack Overflow用户

发布于 2011-01-04 19:33:26

您应该在"willDisplayCell“委托方法中进行颜色更改,而不是在"cellForRowAtIndexPath”中创建它时进行更改。否则,当向电池添加例如附件时,它可能不会粘住或可能显示不好。

查看这篇文章以了解更多细节:Setting background color of a table view cell on iPhone

票数 0
EN

Stack Overflow用户

发布于 2013-04-04 16:57:12

代码语言:javascript
运行
复制
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];
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3572659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档