【问题标题】:Customize UITableView section border color for each section为每个部分自定义 UITableView 部分边框颜色
【发布时间】:2011-01-28 20:14:25
【问题描述】:

我正在使用带有分组的 UITableView。我的第一组我建立了一个没有背景颜色的自定义单元格,我还想删除单元格周围的边框。我怎样才能只为一个部分执行此操作?

对于我的第一个单元格,我想将边框/分隔符样式设置为 [UIColor clearColor]。

编辑:Apple 在他们的通讯录应用中做到了这一点,我想设计类似的东西。

【问题讨论】:

    标签: iphone ios uitableview


    【解决方案1】:
    -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if(indexPath.section == 0){
    
    cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
    
      }
    }
    

    【讨论】:

    • 谢谢!我也让它直接在 cellForRowAtIndexPath 内部工作!
    【解决方案2】:

    我相信 Apple 使用的联系人标题是 tableView:viewForHeaderInSection: 用于部分 0,而不是第一部分中的单元格。您仍然可以指定透明背景,细条纹将显示在其后面。边框将不存在,因为分组的表格视图部分标题没有边框。

    无论您是在 Interface Builder 中构建自定义单元还是使用代码,将这些视图从 UITableViewCell 迁移到 UIView 以与 tableView:viewForHeaderInSection: 一起使用应该是一项相当简单的任务。

    我不知道您是否可以保留 1 部分的 详细信息 标题,除非您制作包含该单词的标签并将其添加到部分 @ 987654327@ 手动查看标题。

    【讨论】:

    • 如果您将其更改为节标题,则它不会像以前那样滚动。即它会停留在屏幕顶部,而该部分在其下方滚动,这可能是您不想要的。
    【解决方案3】:

    如果我理解你的问题,你应该在 cellForRawIndexPath 中添加-

    if(indexPath.section==0){
    
    //set the style you wish to add only to the first section
    
    }
    

    祝你好运

    编辑

    我为此使用了这个功能-

    +(void)setTransparentBgToCell:(UITableViewCell*)cell{
            UIView *backgroundView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
            backgroundView.backgroundColor = [UIColor clearColor];
            cell.backgroundView = backgroundView;
            [backgroundView release];
            cell.selectionStyle=UITableViewCellSelectionStyleNone;
            cell.textLabel.backgroundColor = [UIColor clearColor];
            cell.detailTextLabel.backgroundColor = [UIColor clearColor];
    }
    

    沙尼

    【讨论】:

    • 是的,但我能找到的只是为整个 tableView 设置它: tableView.separatorColor = [UIColor clearColor]; tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    • 你是对的。我添加了一个我在我的一个应用程序中使用的功能,试试 that.shani
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 2023-03-14
    • 2013-08-07
    • 2010-10-23
    • 2017-06-26
    相关资源
    最近更新 更多