Skip to content

Instantly share code, notes, and snippets.

@elmoswelt
Created April 25, 2023 12:47
Show Gist options
  • Save elmoswelt/3739172d6bf3dbf803bd20fe9b2dfc2e to your computer and use it in GitHub Desktop.
Save elmoswelt/3739172d6bf3dbf803bd20fe9b2dfc2e to your computer and use it in GitHub Desktop.
Generic Cell's
public class ContainerCollectionViewCell<ContainedView: UIView>: UICollectionViewCell {
// MARK: - Properties
public let containedView = ContainedView()
//MARK: Initialization
override public init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: - Setup
private func setup() {
backgroundColor = .clear
contentView.addSubview(containedView)
containedView.pin(to: contentView)
}
}
public class ContainerTableViewCell<ContainedView: UIView>: UITableViewCell {
//MARK: Public
public let containedView = ContainedView()
//MARK: Initialisation
override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
setup()
}
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
//MARK: Setup
private func setup() {
contentView.addSubview(containedView)
containedView.pin(to: contentView)
backgroundColor = .clear
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment