菜鸟教程小白 发表于 2022-12-12 11:25:58

ios - uitableviewcell 顶部的灰色分隔线


                                            <p><p>在过去的几个小时里,我一直在努力解决这个问题,但我找不到解决办法...
在 UITableView 中,我插入了一个自定义 UITableViewCells 列表,其中包含所有不同的颜色。这些颜色是 UIView 的一部分,它充当 tableviewCell 的 backgroundView 当我初始化 UITableView 时,我设置了</p>

<pre><code>self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
</code></pre>

<p>但是,在顶部的每个单元格上仍然有一条细灰线。此行不是来自 textLabel(此标签的框架比实际单元格小),也不是来自包含颜色的 UIView(layer.borderwidth = 0.0f,颜色为 clearColor)。</p>

<p> <img src="/image/YjnjZ.png" alt="Tableview with cells"/> </p>

<p><strong>编辑</strong></p>

<p>好的,我发现这些线条确实来自包含背景颜色的 UIView。然而禁用它们,当我重新排序它们时会导致透明单元格,这是此 UIView 中的 drawRect 的结果,使用以下代码绘制 UIView:</p>

<pre><code>CGContextSetShouldAntialias(UIGraphicsGetCurrentContext(), true);
CGContextFillRect(UIGraphicsGetCurrentContext(), self.bounds);
</code></pre>

<p>有人知道解决这个问题的方法吗?</p>

<p><strong>已解决</strong></p>

<p>我很愚蠢,但是单元格没有背景 View ...所以通过在自定义单元格类中添加这两行,问题就解决了!</p>

<pre><code>self.backgroundView = [ initWithFrame:CGRectZero];
self.backgroundView.backgroundColor = ;
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我找到了我的问题的解决方案。通过在 cell 类的 backgroundView 中设置一个 UIView,并用白色背景填充它,这样就解决了这个问题。</p>

<p><code>self.backgroundView = [ initWithFrame:CGRectZero];</code>
<code>self.backgroundView.backgroundColor = ;</code></p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - uitableviewcell 顶部的灰色分隔线,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/25325010/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/25325010/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - uitableviewcell 顶部的灰色分隔线