我有一个UITableView
文章列表。当用户点击一篇文章时,它会有一个转场,然后当他们回到列表时,我希望该文章被标记为“已读”。在这种情况下,标记为已读意味着单元格看起来应该是灰色的。我试图通过创建 aUIView
并将其用作该单元格上的覆盖来做到这一点。
这是我最近的尝试:
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.autoresizingMask = [.flexibleWidth, .flexibleHeight]
在将其添加为子视图之前,使其扩展到所有单元格。
但是,我建议Storyboard
在单元格内的文件中制作此叠加视图,在此处将其公开为IBOutlet
ant 只需isHidden
在updateCellProperties
方法中设置值。
祝你好运!
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句