Created
May 10, 2017 19:24
-
-
Save iThinker/0adbfd1391c455c7a8c6fa11aa25e36b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class TableViewContainerCell<Content: UIView>: UITableViewCell { | |
var content: Content | |
override init(style: UITableViewCellStyle, reuseIdentifier: String?) { | |
if let viewFromNib = Content.loadDefaultNib() { | |
content = viewFromNib | |
} | |
else { | |
content = Content(frame: .zero) | |
} | |
super.init(style: style, reuseIdentifier: reuseIdentifier) | |
self.embedContent() | |
} | |
required init?(coder aDecoder: NSCoder) { | |
fatalError("init(coder:) has not been implemented") | |
} | |
func embedContent() { | |
let containerView = self.contentView | |
containerView.addSubview(self.content) | |
self.content.translatesAutoresizingMaskIntoConstraints = false | |
containerView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-0-[view]-0-|", options: [], metrics: nil, views: ["view": self.content])) | |
containerView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-0-[view]->=0-|", options: [], metrics: nil, views: ["view": self.content])) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment