gpt4 book ai didi

swift - 如何使单元格及其元素显示为灰色?

转载 作者:行者123 更新时间:2023-11-30 10:58:13 26 4
gpt4 key购买 nike

我有一个 UITableView,它是文章列表。当用户点击一篇文章时,会出现一个segue,然后当他们返回列表时,我希望该文章被标记为“已读”。在这种情况下,标记为已读意味着单元格应该显示为灰色。我尝试通过创建一个 UIView 并将其用作该单元格上的覆盖层来实现此目的。

这是我最新的尝试:

class PublicationTableViewCell: UITableViewCell {

@IBOutlet weak var publicationTitle: UILabel!
@IBOutlet weak var authorName: UILabel!
@IBOutlet weak var authorInitials: UILabel!
@IBOutlet weak var authorImage: UIImageView!
@IBOutlet weak var bottomBorder: UIView!

var pub: PublicationModel?

func updateCellProperties(publication: PublicationModel, indexPathRow: Int) {
pub = publication if let isRead = publication.isRead {

// this is the overlay that I can’t get to work
let readOverlayView = UIView()
readOverlayView.tintColor = UIColor.grey3
readOverlayView.alpha = 0.5
self.addSubview(readOverlayView)

// I was greying out just the title like this. This will go away if I get the overlay to work
publicationTitle.textColor = isRead ? UIColor.grey3 : UIColor.grey1

}
}

// some helper methods…

}

我已经单步调试了代​​码,并确认对于已阅读的文章,isRead 标志为 true 并且正在执行创建 readOverlayView 的代码。

我希望项目上的所有 UI 元素都变灰,这就是为什么我不尝试更改单元格的背景颜色。

  • 为什么我的readOverlayView对单元格的外观没有影响
  • 有没有更好的方法来达到我想要的效果?

谢谢

最佳答案

你可以这样做:

readOverlayView.autoresizingMask = [.flexibleWidth, .flexibleHeight]在将其添加为 subview 之前,使其在所有单元格上展开。

但是,我建议在 Storyboard 中制作此覆盖 View 文件在单元格内,将其公开为 IBOutlet Ant 简单设置isHiddenupdateCellProperties方法。

祝你好运!

关于swift - 如何使单元格及其元素显示为灰色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53711568/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com