菜鸟教程小白 发表于 2022-12-13 03:03:21

ios - 选择 UITableViewCell 时标签背景颜色发生变化


                                            <p><p>我在 UITableViewCell 中添加了一个自定义标签。它的背景颜色为红色,字体为白色。当我选择任何单元格时,所选单元格的标签背景颜色变为灰色。 </p>

<p>供引用,我正在添加代码</p>

<pre><code>let lblUnreadCount = cell?.viewWithTag(3) as! UILabel
let size:CGFloat = 20.0
lblUnreadCount.bounds = CGRect(x: 0.0, y: 0.0, width: 28.0, height: 20.0)
lblUnreadCount.layer.cornerRadius = size / 2
lblUnreadCount.layer.borderWidth = 1.0
lblUnreadCount.layer.backgroundColor = UIColor.red.cgColor
lblUnreadCount.layer.borderColor = UIColor.red.cgColor
</code></pre>

<p>作为引用,我还添加了一个屏幕截图。
<a href="/image/GaSQ3.png" rel="noreferrer noopener nofollow"><img src="/image/GaSQ3.png" alt="enter image description here"/></a> </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>改变的不是标签的背景,而是单元格本身。在你的 <code>cellForRow</code> 方法中,在你 <code>dequeued</code> 单元格之后,使用这个</p>

<pre><code>cell.selectionStyle = .none
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 选择 UITableViewCell 时标签背景颜色发生变化,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/46904167/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/46904167/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 选择 UITableViewCell 时标签背景颜色发生变化